Re: Sharing variable values among PHP files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Coments inline...

<snip>
On 01 Apr,2003 at 10:04 Mustafa Ocak wrote:

> 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.

-- 
Ronan
e: ronan@thelittledot.com
t: 01903 739 997
w: www.thelittledot.com

The Little Dot is a partnership of
Ronan Chilvers and Giles Webberley

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux