|
![]() session_register
Register one or more global variables with the current session
(PHP 4, PHP 5)
Related Examples ( Source code ) » session_register Examples ( Source code ) » Encoding Data Examples ( Source code ) » The syntax of the session_start () function Examples ( Source code ) » Deleting Existing Session Variables Examples ( Source code ) » Modifying Session Variables Examples ( Source code ) » Registering an Array Variable with a Session Examples ( Source code ) » Register session variables Examples ( Source code ) » Unregistering Variables Code Examples / Notes » session_registergianni_t76
You don't need to serialize an object before adding it to a session var example: include("class.exmaple.php"); $obj = new exampel (); $_SESSION['obj']=$obj; and to resume the object: include("class.example.php"); $obj = $_SESSION['obj']); creepers
sometimes you know everything was right but you still get an error Cannot send session cache limiter - headers already sent (output started at blah blah...; you may spend an hour until you discover that your php tag was at the second line of your script. this is true specially when you are under pressure..i hope this will help...
martijn
Please note that if you use a "|" sign in a variable name your entire session will be cleared, so the example below will clear out all the contents of your session. <?php session_start(); $_SESSION["foo|bar"] = "foo"; ?> It took me quite some time finding out why my session data kept disappearing. According to this bugreport this behaviour is intended. http://bugs.php.net/bug.php?id=33786 guideng
Make sure you put session_start() at the beggining of your script. My sessions kept unsetting and I finally figured out why. On my script, session_start() has to be said and uses cookies to set the session. But I was outputting html prior to calling session_start(), which prevented it from succeeding becouse it uses the header function to place the cookies. Once html has been outputed, session_start() can't use the header function to set cookies, hence session_start() fails and no session can be started. baldanders
If you are using sessions and use session_register() to register objects, these objects are serialized automatically at the end of each PHP page, and are unserialized automatically on each of the following pages. This basically means that these objects can show up on any of your pages once they become part of your session.
mikej
I've noticed that if you try to assign a value to a session variable with a numeric name, the variable will not exist in future sessions. For example, if you do something like: session_start(); $_SESSION['14'] = "blah"; print_r($_SESSION); It'll display: Array ( [14] => "blah" ) But if on another page (with same session) you try session_start(); print_r($_SESSION); $_SESSION[14] will no longer exist. Maybe everyone else already knows this, but I didn't realize it until messing around with a broken script for quite a while. hairguy
I wasted about two days trying to figure out why some of my session data was being lost. The problem occurred intermittently and I was nearly convinced it had to be a PHP bug. Since my session data was being stored in mysql, I finally thought to check the definition of the session table. The session data was stored in a column of type 'text' (which can only hold 65,535 bytes of data). Changing the session column to type 'mediumtext' (which can hold 16,777,215 bytes) solved the problem. Perhaps this tip will help someone else who may be experiencing similar session loss problems. dominik-ruess
Do not even think of using "global" together with "$_SESSION": <?php // Will only work on some servers (or some PHP-Versions - I don't know): function test() { global $_SESSION; $_SESSION["test"]=1; } // correct way: function test() { $_SESSION["test"]=1; } ?> took me hours to recognize :/ |
Change Language![]() session_cache_expire session_cache_limiter session_commit session_decode session_destroy session_encode session_get_cookie_params session_id session_is_registered session_module_name session_name session_regenerate_id session_register session_save_path session_set_cookie_params session_set_save_handler session_start session_unregister session_unset session_write_close |