Forum Moderators: coopster
Short version of the story: PHP session values are not being stored, though session files are being created with the default values for my website.
Long version: Sessions are being started, and the default values for each of the session variables (user id, permissions, etc) are being stored properly in the directory where the webserver stores session variables. However, when a person logs into the site, and the script attempts to update the session variables, but the values are not actually being stored the the session file, so when the user is redirected back to the page that they came from, it still shows that they are not logged in.
Complication: I wrote a small little test script using sessions.. and it works.. it is storing the session value properly. I don't know what is wrong.
Code that isn't working:
$_SESSION['user_id'] = $permissions['ID'];
$_SESSION['user_name'] = $permissions['Name'];
$_SESSION['is_logged_in'] = true;
// site permissions
$_SESSION['site_admin'] = ($permissions['Site_Admin'] == "Y")? true : false;
$_SESSION['news_mod'] = ($permissions['News_Mod'] == "Y")? true : false;
$_SESSION['view_full_db'] = ($permissions['View_Full_DB'] == "Y")? true : false;
$_SESSION['db_mod'] = ($permissions['DB_Mod'] == "Y")? true : false;
$_SESSION['fiction_mod'] = ($permissions['Fiction_Mod'] == "Y")? true : false;
$_SESSION['content_mod'] = ($permissions['Content_Mod'] == "Y")? true : false;
Simple code that does work:
$_SESSION['count'] = isset($_SESSION['count'])? $_SESSION['count'] + 1 : 1;
echo "You've seen this page {$_SESSION['count']} times.\n";
Any thoughts or suggestions?
Thank you..
The first thing I usually do when troubleshooting SESSIONs is exit my script at certain points to determine what is in a $_SESSION variable or even when the SESSION variables are being cleared. So, in this case I might start right before the redirect occurs. Something as simple as
print '<pre>';
print_r($_SESSION);
print '</pre>';
exit;