note 88731 modified in function.session-start by danbrown

From: Date: Thu, 05 Feb 2009 02:28:45 +0000
Subject: note 88731 modified in function.session-start by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-150241@lists.php.net to get a copy of this message
Here is some info about how to use SID with session_start(). Experiment run on WAMPserver, PHP version 5.2.6. Using FireFox 3.0. The definition found at http://www.php.net/manual/en/session.constants.php describes SID is a “pre-defined constant” containing either: 1). the session name and session ID in the form of "name=ID" . This is the same name as would be returned by session_name(), and the same id as would be returned by session_id(). 2). Or an empty string, if the session ID was set in an appropriate session cookie. Example code: <?php session_start(); echo '<a href="page2.php?' . SID . '">page2</a>'; ?> This code will yield in the browser one of the following: a). “page 2” (as a hyperlink, but mouseover shows the link is to something in the form of http://www.example.com/page2.php?PHPSESSID=e2bd7072.... ) b). “page 2” (as a hyperlink, but mouseover shows http://www.example.com/page2.php? ) Which result is determined by whether or not the browser is sending a matching session cookie back to the script. Result “a” above always appears at least initially since the script hasn’t yet set a cookie and neither has it been done automatically yet by the php.ini setting session.use_cookies. However, after refreshing or using the back button, the form in "b" will appear because then the cookie exists (either you set it or session.use_cookies did it automatically). --was-- Here is some info about how to use SID with session_start(). Experiment run on WAMPserver, PHP version 5.2.6. Using FireFox 3.0. The definition found at http://www.php.net/manual/en/session.constants.php describes SID is a “pre-defined constant” containing either: 1). the session name and session ID in the form of "name=ID" . This is the same name as would be returned by session_name(), and the same id as would be returned by session_id(). 2). Or an empty string, if the session ID was set in an appropriate session cookie. Example code: <?php session_start(); echo '<a href="page2.php?' . SID . '">page2</a>'; ?> This code will yield in the browser one of the following: a). “page 2” (as a hyperlink, but mouseover shows the link is to something in the form of http://www.mysite.com/page2.php?PHPSESSID=e2bd7072.... ) b). “page 2” (as a hyperlink, but mouseover shows http://www.mysite.com/page2.php? ) Which result is determined by whether or not the browser is sending a matching session cookie back to the script. Result “a” above always appears at least initially since the script hasn’t yet set a cookie and neither has it been done automatically yet by the php.ini setting session.use_cookies. However, after refreshing or using the back button, the form in "b" will appear because then the cookie exists (either you set it or session.use_cookies did it automatically). http://php.net/manual/en/function.session-start.php

« previous php.notes (#150241) next »