Jump to content

Setting Session Variables From Within Class


jh_dempsey

Recommended Posts

Hey All

Im having a real headscratch here when trying to set session variables from inside a class

I have a page called uni_login.php which includes the file with my class in, and then creates a new instance of the class.

One of the functions in the class is the do_login function, and this function check for correct login details, and then will grab all the info from the database and attempt to store this info inside a session so i can get to it later.
Im doing it like this:

[code]foreach($row as $key => $value)
{
$_SESSION[$key] = $value;
}[/code]

All seems to work fine because if i do a var_dump($_SESSION) on my uni_login.php page after i have called the do_login() function then it all seems to display fine. All the values are there along with the correct array keys.

Now...

If i go to another page (index.php), i start a session with session_start(); and attempt to output some of the variables from within my session. Nothing happens. They are all completley blank. Doing a var_dump($_SESSION) on the index.php page shows it to be completely empty.

Ive checked that the session id being used is the same on both pages, and it is, so thats not the problem.

Next i tried just typing this somewhere on my uni_login.php page
[code]$_SESSION[test_var] = "Test Success";[/code]

Now if i go to my index.php page and try and print this variable, it works fine.

So what am i doing wrong?? Is there something special i need to do to store session variables from within a class??

Thanks
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.