Passing Session IDs in the Query String


So far you have relied on a cookie to save the session ID between script requests. On its own, this method is not the most reliable way of saving state because you cannot be sure that the browser will accept cookies. You can build in a failsafe, however, by passing the session ID from script to script embedded in a query string. PHP makes a name/value pair available in a constant named SID if a cookie value for a session ID cannot be found. You can add this string to any HTML links in session-enabled pages:

<a href="page2.html?<?php echo SID; ?>">Another page</a>


It will reach the browser as

<a href="page2.html?PHPSESSID=08ecedf79fe34561fa82591401a01da1">Another page</a>


The session ID passed in this way will automatically be recognized in the target page when session_start() is called, and you will have access to session variables in the usual way.




Sams Teach Yourself PHP, MySQL And Apache All in One
Sams Teach Yourself PHP, MySQL and Apache All in One (3rd Edition)
ISBN: 0672328739
EAN: 2147483647
Year: 2004
Pages: 327

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net