Reputation: 1222
If I write the following code:
session_start();
$_SESSION['user_id']='daniel';
the variable stays fine as long as I'm on the page on which it was created, and the second I try to call $_SESSION['user_id']
from another page, I don't get a response.
Can anyone tell me what mistake I'm making?
Upvotes: 0
Views: 540
Reputation: 340171
You should be using session_start()
on every page you want to use sessions on.
Upvotes: 13
Reputation: 7854
Ensure that the PHPSESSID cookie is actually being set, and that no headers / content have been sent before you call session_start()
Upvotes: 1
Reputation: 625007
As long as:
session_start()
on the other page. Note: you don't make this call once. You do it on every page that wants to access the session information;then it can see it. Construct a simple test case and verify this and then work out why what you're doing is different.
Upvotes: 4