[thelist] Apache mod_rewrite and PHP SID

Liam Delahunty ldelahunty at britstream.com
Wed Feb 5 05:08:02 CST 2003


Tony Light wrote:
< some stuff about mod_rewrite then... >
Well, I use PHP sessions.  If the user has Cookies totally switched off,
then sessions will not work unless you pass the special SID variable around
appended to all your internal links.
e.g. <a href="http://www.mydomain.com/1?<?php echo(SID)?>">

which after PHP parsing comes out something like:
<a href="http://www.mydomain.com/1?"> .... if cookies are enabled
<a href="http://www.mydomain.com/1?PHPSESSID=abcdefgh123456789"> .... if
cookies are not enabled.
</end>

While I can't answer you question about mod_rewrite as I've never played
with it, the following snippet will test the cookie (ShoppingCart) and
append the session only if it's needed. Therefore no extra "?" in the URI.
Obviously watch for wrap...
print ("<a href=\"../onlinesales/shop.php".(!$ShoppingCart?
"?session=$session":"")."\">Shop</a><br>\n");

Obviously, when there's other fields I append it to the end of the URL with
an ampersand.
<a href=\"shop.php?category_id=$category_id".(!$ShoppingCart?
"&session=$session":"")."\">$category</a>

<OT BIT>
Roddy Frame (Aztec Camera) is playing a secret gig in London tonight, see
http://www.biggerbrighterbetter.com for more details.
...Sorry...
</OT>

Kind regards,
Liam Delahunty
Mega Products Limited, 10-11 Moor Street, Soho, London W1D 5NF
http://www.onlinesales.co.uk/ Open Source PHP/MySQL E-commerce




More information about the thelist mailing list