I found a very tricky problem with a wrapper class that I had coded for
setting and getting variables in $_SESSION super global array. The class is
an utility class having function
HttpRequest::GetSessionParm() and HttpRequest::SetSessionParm() to get and
set values in $_SESSION resply. I was under the impression that $_SESSION
need not be defined as 'global' within class methods but this wrapper class
initially failed when the system was deployed on FreeBSD machine. It worked
when I added 'global $_SESSION' within the above mentioned static methods. I
am not aware of the reason. It worked fine on my machine (windows 2000
professional). Any reason available for the problem will be appreciated.
Here is the code for those two functions
/**
* returns the value for parameter stored in $_SESSION
* if $escaped is true, the returned value is first
* escaped using addslashes function before returning
*/
static function GetSessionParm($param,$escaped=false)
{
global $_SESSION;
if (isset(self::$data["session"]))
if (array_key_exists($param, self::$data["session"]))
return (($escaped) ? addslashes(self::$data["session"][$param]) :
self::$data["session"][$param]);
else
return null;
else
return null;
}
/**
* sets a value in session
*/
static function SetSessionParm($param,$value)
{
global $_SESSION;
$_SESSION[$param] = $value;
self::$data["session"] = $_SESSION;
}
if I remove the global $_SESSION the session data isnot being maintaned from
page to page
Thanx,
Vamsi
setting and getting variables in $_SESSION super global array. The class is
an utility class having function
HttpRequest::GetSessionParm() and HttpRequest::SetSessionParm() to get and
set values in $_SESSION resply. I was under the impression that $_SESSION
need not be defined as 'global' within class methods but this wrapper class
initially failed when the system was deployed on FreeBSD machine. It worked
when I added 'global $_SESSION' within the above mentioned static methods. I
am not aware of the reason. It worked fine on my machine (windows 2000
professional). Any reason available for the problem will be appreciated.
Here is the code for those two functions
/**
* returns the value for parameter stored in $_SESSION
* if $escaped is true, the returned value is first
* escaped using addslashes function before returning
*/
static function GetSessionParm($param,$escaped=false)
{
global $_SESSION;
if (isset(self::$data["session"]))
if (array_key_exists($param, self::$data["session"]))
return (($escaped) ? addslashes(self::$data["session"][$param]) :
self::$data["session"][$param]);
else
return null;
else
return null;
}
/**
* sets a value in session
*/
static function SetSessionParm($param,$value)
{
global $_SESSION;
$_SESSION[$param] = $value;
self::$data["session"] = $_SESSION;
}
if I remove the global $_SESSION the session data isnot being maintaned from
page to page
Thanx,
Vamsi