Page 1 of 1

Problem with $_SESSION

Posted: Wed Aug 23, 2006 8:52 am
by jaff
Hi!

I almost try everything that's why I try here.

I do a site that use $_SESSION. In the login page, I put date in 5 $_SESSION variables.
But in the second page, all my session variables are empty.. I don't understand, session variable are supposed to keep the variable across the web site, no?

I don't have the code on this computer, but here is what I do!

Code: Select all

<?
session_start();
session_register("v1");
session_register("v2");
session_register("v3");
session_register("v4");
session_register("v5");

$_SESSION("v1") = "something"
 echo $_SESSION("v1");
It show something on this page...

And then, on the other page:

Code: Select all

echo $_SESSION("v1");
It show nothing.. like my $_Session disapear!
Please help!

If you need the code, maybe I can send a part of it this afternoon
Thank for your help in advance!

Posted: Wed Aug 23, 2006 8:59 am
by Jenk
A few pointers :)

you must use session_start(); on every page you require session variables.

session_register() is deprecated, you only need to assign the value to the $_SESSION superglobal and PHP will save the session data for you.

$_SESSION superglobal is an array, not a function, thus the correct syntax is:

Code: Select all

$_SESSION['var'] = 'foo';
Also, when posting PHP code, please use the PHP tags and not CODE tags, thank you :)

Posted: Wed Aug 23, 2006 8:59 am
by Oren
First, stop using session_register().
Second, you have to call session_start() before you print the data within $_SESSION['v1'] on the second page.

Thanks!

Posted: Wed Aug 23, 2006 10:22 am
by jaff
Thank you very much. I will try this this evening! :)