note 33501 added to function.session-set-save-handler

From: Date: Fri, 27 Jun 2003 20:16:25 +0000
Subject: note 33501 added to function.session-set-save-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-51113@lists.php.net to get a copy of this message
After more than one month working with and trying to understand sessions . I've tried a lot of things. My contribution is a simply explanation of how the function session_set_save_handler works. You have to understand on what order does the functions open, read, write , destroy and gc are called. Pay attention on the code bellow: <? session_name("test"); session_start(); $_SESSION["var1"] = "test1"; //session_register(var...), whatever echo "anything" ?> The script will work in the follwing sequence. 1st, a session_id will be set (if it hans't been set yet) 2nd, php will read ALL session variables 3rd, when you register a variable into a a session, it can be accessed only by the current file, unless your script is finalized or a call to session_write_close() is made. 4th, this script would print "anything" 5th, finalizing your script, php write all session variables, veryfing if they were been unset or not, into a file, database, whatever you work for. SO, try to build your code base on the information that session variables are only registered when the scripts ends, or a call to session_write_close() is made. You have to take care when you use session handling with databases. P.S. how good is my english? ---- Manual Page -- http://www.php.net/manual/en/function.session-set-save-handler.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33501 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33501&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33501&report=yes

« previous php.notes (#51113) next »