PHP 4.0 Bug #7072: Session fails to write data to session file
| From: | jsisson at hotship dot com | Date: | Fri, 06 Oct 2000 20:39:25 +0000 |
| Subject: | PHP 4.0 Bug #7072: Session fails to write data to session file | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-34404@lists.php.net to get a copy of this message | ||
From: jsisson@hotship.com
Operating system: Linux (Mandrake 7)
PHP version: 4.0.2
PHP Bug Type: *Session related
Bug description: Session fails to write data to session file
When using the attached code as a custom session handler, everything works fine, but when I call the
function getenv(SCRIPT_NAME) inside the write() method, the session will no longer write session
data to disk.
The logsession() function logs session operations, and will thus show the lack of write() operations
when the line:
# logsession("Writing $id", getenv(SCRIPT_NAME));
is uncommented.
My configure line (from PHPINFO):
'./configure' '--with-mysql=/usr/local/mysql'
'--with-pdflib=/usr/local/pdf' '--with-tiff-lib'
'--with-apache=../apache_1.3.12' '--with-ftp' '--with-xml'
'--enable-track-vars'
Attached Code:
<?
function logsession($message, $script) {
$newMessage = preg_replace("/[\%]/", "", $message);
openlog("Diag", LOG_PID, LOG_LOCAL1);
syslog(LOG_ERR , "Session -> $newMessage (" . ")");
closelog();
}
function open($save_path, $session_name) {
global $sess_save_path, $sess_session_name;
global $HTTP_GET_VARS;
logsession("Opening...", "");
$sess_save_path = $save_path;
$sess_session_name = $session_name;
return TRUE;
}
function close() {
logsession("Closing...", "");
return TRUE;
}
function read($id) {
global $sess_save_path, $sess_session_name;
logsession("Reading $id", "");
$sess_file = "$sess_save_path/sess1_$id";
if ($fp = @fopen($sess_file, "r")) {
$sess_data = fread($fp, filesize($sess_file));
return $sess_data;
}
else {
return "";
}
}
function write($id, $sess_data) {
global $sess_save_path, $sess_session_name;
# logsession("Writing $id", getenv(SCRIPT_NAME));
$sess_file = "$sess_save_path/sess1_$id";
if ($fp = @fopen($sess_file, "w")) {
return fwrite($fp, $sess_data);
}
else {
return FALSE;
}
}
function destroy($id) {
global $sess_save_path, $sess_session_name;
logsession("Destroying $id", "");
$sess_file = "$sess_save_path/sess1_$id";
return @unlink($sess_file);
}
function gc($maxlifetime) {
return TRUE;
}
session_set_save_handler("open", "close", "read", "write",
"destroy", "gc");
?>
Full Bug description available at: http://bugs.php.net/?id=