PHP Classes

Session In DB but can't see it in $_SESSION

Recommend this page to a friend!

      Zebra_Session, a wrapper for PHP’s default session handling functions, using MySQL for storage  >  All threads  >  Session In DB but can't see it in...  >  (Un) Subscribe thread alerts  
Subject:Session In DB but can't see it in...
Summary:Need help getting data to be read out of $_SESSION.
Messages:2
Author:Rone
Date:2009-10-11 05:27:06
Update:2009-11-07 16:02:00
 

  1. Session In DB but can't see it in...   Reply   Report abuse  
Picture of Rone Rone - 2009-10-11 05:27:06
I need a bit of help and can't seem to figure out what is going on. I can't get this class to read data fromt he session properly. After login, I call a "login_process.php" page which includes the class file, selects the database where I have the table stored that holds the session data, I add data to the $_SESSION var and during debugging all the data gets stored in $_SESSION just fine (inside this page); I checked the database and its all there as well, so I know its set up properly (at least part of it). However, when I do a redirect to the landing page and try to use the $_SESSION to retrieve the username (i.e $_SESSION["username"]) nothing shows up. On the landing page,I include a header page. Inside the header I have included the class for the php session script and I've instantiated an object. I've also selected the appropriate database, just like I did in the login_process.php page. When I var_dump($_SESSION) it says there is nothing there, eventhough in the login_process.php page I set everything and its still inside the database table. If I hardcode a $_SESSION["something"]="hi mom"; in the landing page, then dump the $_SESSION, it shows the "hi mom" value and the "something" variable. This is giving me the impression that at this point the PHP is still using "file-based" storage, instead of the database...I confirmed that by loooking into the database where the session var should be stored and its not there. I updated the php.ini file directly on my local computer to 'session.save_handler = user', but then it breaks my phpmyadmin stuff and created more problems for me.

I've been debugging for hours and am at a loss. Is there anyone who has some advice, or tips that could help me? It's odd to me that it will work in the login_process.php page, but when that page redirects using header(location), the receiving page can't see the variables?

Thanks in advance.

Aaron

  2. Re: Session In DB but can't see it in...   Reply   Report abuse  
Picture of Noobita Noobita - 2009-11-07 16:02:00 - In reply to message 1 from Rone
Mr Aron,

I'm new to this class as well but since I understand a little bit about this code so I think I should share with you. Actually, we can store our session information example $_SESSION["value1"]= $username and $_SESSION["value2"]=$userlevel only by follow the exact code and I have try to change such as $_SESSION["username"]=$username and it cannot work, and the data in the field session_data inside the session_data table is empty. Since, the data in the filed session_data is array data type so you can retrieve your data such as $username by type print_r($_SESSION["value1"]); and it will print the username for you and also print_r($_SESSION["value2"]); for userlevel. I've try this code for my login testing and it work fine, but I have another problems, I don't know how to set timeout for the session. If you know it, I'm really appreciated if you can help me on it.