Reputation: 328
Checked all over the web and tried all possible solutions written about problems with sessions.
I have 3 pages: the 1st page reads some data from redirected form and stores 4 variables in session. Here is first session id generated and if I check print_r($_SESSION) all is ok.
The form from this page on submission goes to 2nd page where data is stored in mysql database (no session manipulation here), and then "meta" redirects to 3rd page.
Here I try to read variables from session, but instead a new session is generated. If I look in my server tmp dir both sessions are here.
Why is new session generated instead of reading from first session?
Any other ideas?
Code is simple session like this:
1st php
session_start();
$_SESSION['id'] = $id;
2nd page tried
session_start();
print_r($_SESSION);
output is Array{ id -> }
so only empty variable
3rd page
session_start();
$id = $_SESSION['id'];
echo $id;
and output is ''
Upvotes: 1
Views: 237
Reputation: 141
I had the same issue for a while and had a very hard time figuring it out. My problem was that I had the site working for a while with the sessions working right, and then all of the sudden everything broke.
Apparently, your session_save_path(), for me it was /var/lib/php5/, needs to have 777 chmod permissions. I accidentally changed it, breaking sessions completely.
To fix, just do sudo chmod -R 777 /var/lib/php5/
(or whatever your session_save_path() is) on linux.
However issues with sessions are very strange and can be caused by a myriad of reasons...
Upvotes: 0
Reputation: 456
It looks like you set the $_SESSION['id'] empty with
$_SESSION['id'] = $id;
cause $id is empty in your Script. Remove this line.
Upvotes: 1