Storing the PHP session ID in a form

If you’ve chosen not to use cookies for PHP sessions, you can append the SID of the session to a URL link in order to keep track of it.

If you want to keep track of SID on page that’s accessed by a form submission, the little code snippet below will strip out the PHPSESSID= from the variable for use as a hidden form value:

$sid = substr(SID, (strpos(SID, "=") + 1), strlen(SID));

And then to use it in your form, add the code below somewhere:

<input type="hidden" name="PHPSESSID" value="<?= $sid ?>" />

This entry was posted in Scripting and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>