note 39575 rejected from ref.session by betz

From: Date: Tue, 03 Feb 2004 00:31:48 +0000
Subject: note 39575 rejected from ref.session by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64573@lists.php.net to get a copy of this message
Note Submitter: Bermi Ferrer Martinez ---- After browser output, nothing you assign to $_SESSION will be saved into $_SESSION array. So be careful!! This wont work <? session_start(); echo "Hi"; $_SESSION[save_me] = "Hola a todos"; ?> After loading this page $_SESSION[save_me] will remain empty. This will work <? session_start(); $_SESSION[save_me] = "Hola a todos"; echo "Hi"; ?> Now $_SESSION[save_me] contains "Hola a todos" There are some cases where is necessary to save values into current session after server output. In this case you can use following function: <? function session_save(){ global $_SESSION; $current_session = $_SESSION; session_destroy(); session_start(); $_SESSION = $current_session; } session_start(); echo "Hi"; $_SESSION[save_me] = "Hola a todos"; //So now is possible to access $_SESSION[save_me] after server output if we run session save session_save(); ?> This time $_SESSION[save_me] will also contain "Hola a todos" I have tested this under Linux and PHP 4.3.4

« previous php.notes (#64573) next »