PHP 4.0 Bug #7072 Updated: Session fails to write data to session file

From: Date: Sat, 02 Dec 2000 14:14:30 +0000
Subject: PHP 4.0 Bug #7072 Updated: Session fails to write data to session file
Groups: php.dev 
Request: Send a blank email to php-dev+get-39843@lists.php.net to get a copy of this message
ID: 7072 Updated by: sas Reported By: jsisson@hotship.com Status: Closed Bug Type: *Session related Assigned To: Comments: Right, some functions cannot be used from a request shutdown handler. Alternatively, you can execute the getenv() in the main body and store the result in a global variable. Thanks for using PHP. Previous Comments: --------------------------------------------------------------------------- [2000-10-06 16:39:24] jsisson@hotship.com 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=7072

« previous php.dev (#39843) next »