session works in PHP5 but not on PHP4

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yingzhao
Forum Newbie
Posts: 2
Joined: Fri May 16, 2008 1:18 pm

session works in PHP5 but not on PHP4

Post 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;
      }
  }
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: session works in PHP5 but not on PHP4

Post 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 :)
There are 10 types of people in this world, those who understand binary and those who don't
suresh_2220
Forum Newbie
Posts: 23
Joined: Mon May 12, 2008 3:13 pm

Re: session works in PHP5 but not on PHP4

Post by suresh_2220 »

Speak to your web hosting company regarding this issue. the problem is from their side.
yingzhao
Forum Newbie
Posts: 2
Joined: Fri May 16, 2008 1:18 pm

Re: session works in PHP5 but not on PHP4

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