Reputation: 37
Hello I have this script below:
<?php
session_save_path('sessions/');
if (!isset($_SESSION)) {
session_start();
}
$loginUsername = A;
if (PHP_VERSION >= 5.1) {session_regenerate_id(true); } else {session_regenerate_id();}
$_SESSION['wallet_email'] = $loginUsername;
echo $_SESSION['wallet_email']
?>
Now I have noticed that once a new session id is generated, I lose the path specified in "session_save_path('sessions/')". This means I am unable to create new sessions.
I actually get the following error.
Warning: Unknown: open(sessions//sess_7af5c5f2f2bd83afff0203cc45190260, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (sessions/) in Unknown on line 0
Please I need urgent help with this.
Upvotes: 0
Views: 1053
Reputation: 11
As has been said, use an absolute path for the parameter to session_save_path( )
. Here's why.
session_save_path( )
and session_regenerate_id( )
do not play nicely together when you use a relative path as a parameter to the former. On my setup (Windows 7, Apache 2.2.25, php 5.3.27), I have the following index.php in c:\www\test:
<?php
date_default_timezone_set( 'America/New_York' );
ini_set( 'session.save_path', './sessions' );
//ini_set( 'session.save_path', 'c:/www/test/sessions' );
session_start( );
if ( !isset( $_SESSION[ 'count' ] )) {
$_SESSION[ 'count' ] = 0;
}
$s1 = session_id( );
$b1 = $_SESSION[ 'count' ]++;
//session_regenerate_id( true );
$s2 = session_id( );
$b2 = $_SESSION[ 'count' ]++;
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Test</h1>
<p><?php echo "$s1: $b1"; ?></p>
<p><?php echo "$s2: $b2"; ?></p>
</body>
</html>
It works just as you would think. When I browse to the script:
When I uncomment the session_regenerate_id( ) command and browse to my script:
When I instead use the second ini_set command (with the full path), it works fine.
The problem seems to be that the regen function confuses PHP: after the regen, PHP writes the session files to c:\Program Files\Apache Software Foundation\Apache2.2\sessions - or, it tries to, but fails if that directory has not already been created. Once I created the second sessions directory, I saw sessions files show up there. But PHP isn't looking there when I call session_start( ), so all the accumulated session knowledge is lost between script invocations.
I only figured this out because I was NOT getting 'directory does not exist' error messages in my 'php_errors.log' - at least, not where I was expecting. I spotted another file by that name in the Apache2.2 directory. In php.ini, I had specified a simple filename for my error_log directive, without the directory path. Any error messages generated before the regen command went to c:\www\test\php_errors.log, but after the regen then went to the file in the Apache directory. So the confusion regen causes appears to extend beyond the session functionality.
Upvotes: 1