note 54881 added to ref.session
| From: | d43m0n at shaw dot ca | Date: | Mon, 18 Jul 2005 20:19:40 +0000 |
| Subject: | note 54881 added to ref.session | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92128@lists.php.net to get a copy of this message | ||
Hello,
I posted earlyer about a issue/bug with Windows servers handling sessions. If you did not read it,
it was based on the fact that if you can use ini_set to re-define the session.save_path to a
relitive location. PHP will instead use it as the exact location with out looking at the directory
where your script is bein execute, thus to say, the session file is not created, or re-read. This of
course only occurs if you use <?php reregister_id() ?>. This function is told to open the
requested session file, obtain the varibles, regenerate an id for that session, create the new
session file and then send the cookie header to the client, of course I did not create this
function, so it may not be in that order.
The following code will generate the error that I speak of, and will not successfully generate the
new session id, of course like I said above, this only accours on PHP 5 & 5.0.4 under the
Windows Environment.
<?php
define("_PATH_TMP", "./tmp");
ini_set('session.save_path', _PATH_TMP);
session_start();
$_SESSION['sid']['obsolete'] = session_id();
session_regenerate_id();
$_SESSION['sid']['replaced'] = session_id();
print_r($_SESSION);
?>
(I know that PHP may use defined constants that include '_' characters at the beggining,
if it has not already, but I am taking that chance atm...)
This can simply be resolved by using the following code:
<?php
define("_PATH_TMP", dirname($_SERVER['SCRIPT_FILENAME']) . "/tmp");
ini_set('session.save_path', _PATH_TMP);
session_start();
$_SESSION['sid']['obsolete'] = session_id();
session_regenerate_id();
$_SESSION['sid']['replaced'] = session_id();
print_r($_SESSION);
?>
As you can see it uses the uses the servers environment to assurtain the exact location to the
script, then locates the next root directory of it, and then allows you to define the tmp directory.
* Of course, you dont need to use a tmp directory, and this issue only occurse when using
subdirectorys, I found that the following works just aswell, but this did not fit my needs!
<?php
define("_PATH_TMP", "./");
ini_set('session.save_path', _PATH_TMP);
session_start();
$_SESSION['sid']['obsolete'] = session_id();
session_regenerate_id();
$_SESSION['sid']['replaced'] = session_id();
print_r($_SESSION);
?>
----
Manual Page -- http://www.php.net/manual/en/ref.session.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54881
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54881&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54881&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54881&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54881&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54881&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54881&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54881&report=yes
Search -- http://master.php.net/manage/user-notes.php