Re: Sharing variable values among PHP files
| From: | Leston Drake | Date: | Tue, 01 Apr 2003 15:35:30 +0000 |
| Subject: | Re: Sharing variable values among PHP files | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26795@lists.php.net to get a copy of this message | ||
For us novices, can you please share how you would do this with register_globals off?
At 01:07 AM 4/1/2003, you wrote:
The method you posted is for register_gkobals on, which it won'tr always (and shouldn't be)! Ronan Chilvers wrote:Coments inline... <snip> On 01 Apr,2003 at 10:04 Mustafa Ocak wrote:-- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.You can store the value in a session variable session_start(); if (isset($_HTTP_SESSION_VARS['your_variable_name'])) {</snip> Rather than using isset() you may need to use session_is_registered(). This is specifically for checking the existence of a session variable. I would do something like <?php // need this on all pages where you want to work with // the session var session_start(); // Check for the existence of the session var and create // it if it doesn't exist if (!session_is_registered("ses_username")) {session_register("ses_username");} // Are we getting a form var thru ? if so pop it into the session var if (isset($frm_username)) {$ses_username = $frm_username;} // then in your scripts you can do do_my_amazing_function($ses_username); ?> As long as you have session_start() at the beginning of each script, $ses_username is now available across scripts. <snip>$value=$_HTTP_SESSION_VARS['your_variable_name']; //get the value }else{ $_HTTP_SESSION_VARS['your_variable_name']=new value; }</snip> Hope that helps.