Page 1 of 1

session works in PHP5 but not on PHP4

Posted: Fri May 16, 2008 2:13 pm
by yingzhao
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.

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;
      }
  }

Re: session works in PHP5 but not on PHP4

Posted: Sat May 17, 2008 3:45 am
by VladSun
I don't think it's PHP version issue related, but a hosting configuration related issue.
I think that most probably, the "session.save_path" is set to none existing path.
Create a file containing

Code: Select all

phpinfo();
on your hosting server, view it in a browser, search for "session" word and see if it matches expectations :)

Re: session works in PHP5 but not on PHP4

Posted: Sat May 17, 2008 1:03 pm
by suresh_2220
Speak to your web hosting company regarding this issue. the problem is from their side.

Re: session works in PHP5 but not on PHP4

Posted: Sun May 18, 2008 4:25 pm
by yingzhao
Thanks for the suggestion. I have contacted my host, and I am waiting for their reply. On another note, I noticed that the major difference between my local environment and their environment is that in my local environment, the registered save handlers is "files user sqlite", while theirs is "files user". I am wondering if that make any difference...

I will post back to let those interested knowing what is going on.