|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9207 User session handler doesn't call write function
Submitted: 2001-02-10 16:01 UTC Modified: 2001-03-01 21:42 UTC
From: jensenta2001 at yahoo dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.0.4pl1 OS: RH Linux 6.2 on Sparc
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.
Block user comment
Status: Assign to:
Bug Type:
From: jensenta2001 at yahoo dot com
New email:
PHP Version: OS:


 [2001-02-10 16:01 UTC] jensenta2001 at yahoo dot com
I'm trying to setup a user session module using a postgre (6.2.3) database.  the script that I'm supplying defines the functions for storing session data.  If I force the session data into the database the read function works and I can retrieve the session data.  However, the write function never gets called so data is never stored in the database.  This is simular to problems reported in #8772 and #9002. There is a difference though.  Those reports indicate that register_globals was off.  In my case register_globals was on.  Here is the script I'm using to test the session module.


$sess_pg = array();
$sess_pg["open_connection"] = true;           // Establish a Pg connection on session startup?
$sess_pg["hostname"]        = "localhost";    // Pg hostname
$sess_pg["port"]            = "5432";         // Pg port
$sess_pg["db"]              = "php_sessions"; // Database where to store the sessions
$sess_pg["table"]           = "sessions";     // Table where to store the sessions

function sess_pg_open($save_path, $sess_name)
    global $sess_pg;

    // Establish a Pg connection, if $sess_pg["open_connection"] is true
    if ($sess_pg["open_connection"])
        $sess_pg["connection"] = pg_pconnect( $sess_pg["hostname"], 
					      $sess_pg["db"]) or die(pg_errormessage($sess_pg["connection"]));


function sess_pg_read($sess_id)
    global $sess_pg;

	echo "HELP ME<br>";
	$query  = "SELECT data ";
	$query .= "FROM ".$sess_pg["table"]." ";
	$query .= "WHERE id = '$sess_id'";
	echo "$query<BR>";

    // Select the data belonging to session $sess_id from the Pg session table    
    $result = pg_exec($sess_pg["connection"], $query) or die(pg_errormessage($sess_pg["connection"])) or die(pg_errormessage($sess_pg["connection"]));

    // Return an empty string if no data was found for this session
    //if(pg_numrows($result) == 0)
    if(!($sess_pg["present"] = pg_numrows($result)))
	echo "Nothing<BR>";

    echo "Records: ".$sess_pg["present"]."<BR>";

    // Session data was found, so fetch and return it
    $row_number	= 0;
    $row = pg_fetch_array($result,$row_number);

    echo "DATA: ".$row["data"]."<BR>";


function sess_pg_write($sess_id, $val)
    global $sess_pg;

        // Write the serialized session data ($val) to the Pg ession table
	$query  = "INSERT INTO ". $sess_pg["table"] ." (id, data, t_stamp) ";
	$query .= "VALUES ($sess_id, $val, now())";
	$result = pg_exec($sess_pg["connection"], $query) or die(pg_errormessage($sess_pg["connection"]));
	// Write the serialized session data ($val) to the Pg ession table
	$query  ="UPDATE ".$sess_pg["table"];
	$query .=" SET data = '$val', t_stamp = now() ";
	$query .=" where id = '$sess_id'";
	$result = pg_exec($sess_pg["connection"], $query) or die(pg_errormessage($sess_pg["connection"]));

function sess_pg_destroy($sess_id)
    global $sess_pg;

    // Delete from the Pg table all data for the session $sess_id
    $query  ="DELETE FROM ".$sess_pg["table"]." ";
    $query .="WHERE id = '$sess_id' ";
    $result = pg_db_query($sess_pg["connection"], $query) or die(pg_errormessage($sess_pg["connection"]));

function sess_pg_gc($max_lifetime)
    global $sess_pg;

    // Old values are values with a Unix less than now - $max_lifetime
    $old = time() - $max_lifetime;

    // Delete old values from the Pg session table
    $result = pg_db_query($sess_pg["connection"], "DELETE FROM ".$sess_pg["table"]." WHERE UNIX_TIMESTAMP(t_stamp) < $old") or die(pg_errormessage($sess_pg["connection"]));

$foo = 10;    
session_set_save_handler("sess_pg_open", "", "sess_pg_read", "sess_pg_write", "sess_pg_destroy", "sess_pg_gc");
echo "foo: $foo";


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-20 13:47 UTC]
How did you verify that the write handler is not called? Note that during the request shutdown the write/close handlers cannot send any data to the browser.
 [2001-02-28 23:51 UTC] jensenta2001 at yahoo dot com
Sorry for the inconvience the problem was in my code.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Sep 18 18:01:26 2020 UTC