php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7072 Session fails to write data to session file
Submitted: 2000-10-06 16:39 UTC Modified: 2000-12-02 09:14 UTC
From: jsisson at hotship dot com Assigned:
Status: Closed Package: Session related
PHP Version: 4.0.2 OS: Linux (Mandrake 7)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jsisson at hotship dot com
New email:
PHP Version: OS:

 

 [2000-10-06 16:39 UTC] jsisson at hotship dot 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");
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-02 09:14 UTC] sas@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 04:01:33 2024 UTC