Hi,

I finished a project on my laptop and now I am trying to take it online. I created the project using php 4.3.6 on my laptop. The server is running php 4.3.2.

My problem is this, in the code bellow, when the user first comes to the page a user class is created for them and stored in a session variable. As they proceed through the site, if there is a class already defined for them, it unserializes it, and uses it. The problem is in the else branch, it does not unserialize properly or something. All 3 echo statments don't work, and the third says the obvious, i am trying to access a member function that does not exist.

This works perfectly on my laptop, but not on the server. I have tried deleting everything off the server and re-uploading also. If you want to see the phpinfo of the server go to www.stockboulevard.com

If you know what is going on please help

Thanks,
papayiya


if(!empty($_SESSION['user'])){
	$user = unserialize($_SESSION['user']);

echo "1cont) ".$user;
echo "2cont) ".$user->db;
echo "3cont) ".$user->db->quote("3214");

}
else {
	session_defaults();
	$db = db_connect();
	$user = new User($db);
	$_SESSION['user'] = serialize($user);

echo "1) ".$user;
echo "2) ".$user->db;
echo "3) ".$user->db->quote("3214");

}

    Hi,

    is session.auto_start enabled on your laptop ? Make sure that the file containing the class declaration is included prior to calling session_start().

    session.auto_start is disabled on the server. In cases where session.auto_start is enabled you might need

    session_write_close();
    include 'classfile.php';
    session_start();
    

    seems like the first two echo statements try to print objects directly.

    Try to use print_r($user) or print_r($user->db) in these cases.

    besides that I think you don't need the serialize and unserialize functions above. You can put objects directly into the session.

    Thomas

      Hi,

      auto start is disbaled. If you want to see the phpinfo of my laptop, go here: http://69.194.153.226

      I have included the class before session start, the site works fine on my laptop, only on the server something goes wrong.

      What did you mean by

      besides that I think you don't need the serialize and unserialize functions above. You can put objects directly into the session.

      Isnt that what I was doing with

      $_SESSION['user'] = serialize($user); 

      Thanks,
      papayiya

        Hi,

        if register_globals is set to off (in your case):

        $_SESSION['user'] = $user;

        If set to on, then use different nameslike

        $_SESION['objUser'] = $user;

        I prefer to use different names.

        In your case the above stuff doesn't matter, it should work anyways. But it might be worth a try.

        What do you get if you do print_r($user) before storing the object in the session and what if your print_r the object after getting it out of the session.

        Thomas

          Thank you so much for your help tsinka.

          Registered globals was off on my laptop, but turned on for the server.

          I turned register globals on for my laptop, and I got the exact same errors. I made the change your said, and it worked.

          Thanks so much.
          papayiya

            Hi,

            glad to hear that.

            I must have something like an 'Eye disease'. I could swear that all settings of register_globals and session.???? where the same on the servers.

            Time to take a rest ... 🙂

            Thomas

              ha, no problem,

              thanks again, if it wasn't for your insight, i would have never seen that.

              papayiya

                Write a Reply...