session works in PHP5 but not on PHP4
Posted: Fri May 16, 2008 2:13 pm
I came across a bizzar problem. My application was developed on a local xampp environment on Windows, which is based on PHP5.1.1. My application works fine on my local xampp environment. Now, I deployed this application to my web hosting site, which is a PHP4.4.2 environment on Linux. For some reason, the session function is broken. That is, once I register a new variable into session on a new page, the old variables (different variables with different names) registered in the session are disgarded. In both of my local environment and my web hosting environment, I turned debugging on, and could not find any error in the execution script. Has anyone encountered similar problem before? I am wondering if the problem is related to PHP configurations.
Here is my code snipt that handles the session data. I can not spot any error, what's more, the same code works perfectly fine in my local environment.
Here is my code snipt that handles the session data. I can not spot any error, what's more, the same code works perfectly fine in my local environment.
Code: Select all
function register($name, $val)
{
if (!isset($_SESSION))
{
session_start();
}
$_SESSION[$name] = $val;
}
function concate($name, $val, $div)
{
if (!isset($_SESSION))
{
session_start();
}
if (isset($_SESSION[$name]))
{
$_SESSION[$name] = $_SESSION[$name] . $div . $val;
}
else
{
$_SESSION[$name] = $val;
}
}
function unregister($name)
{
if (!isset($_SESSION))
{
session_start();
}
if (isset($_SESSION[$name]))
{
unset($_SESSION[$name]);
}
}
function retrive($name)
{
if (!isset($_SESSION))
{
session_start();
}
if (isset($_SESSION[$name]))
{
return $_SESSION[$name];
}
else
{
return null;
}
}