brianmuse Posted January 9, 2008 Share Posted January 9, 2008 I've got kind of an interesting problem that's had me boggled for a few hours. I've used the same basic login/check_login script in all my work and haven't had any problem up until today. The problem I'm having is that when I load a particular page repetitively, the session seems to come and go randomly. The login page does basically: <?php session_start(); header("Cache-control: private"); $user_name = $_POST['user']; $_SESSION['user_name'] = $user_name; $_SESSION['logged_in'] = 1; ?> <SCRIPT language="JavaScript"> <!-- window.location="home.php"; //--> </SCRIPT> check_login.php is loaded first on every page and basically does: <?php session_start(); header("Cache-control: private"); if (!isset($_SESSION['logged_in'])){ $logged_in = 0; //kill the session // or this would remove all the variables in the session, but not the session itself session_unset(); // this would destroy the session variables session_destroy(); } else { $logged_in = 1; } ?> For testing purposes, I made the first line after that: echo $_SESSION['username']." ".$logged_in; When I hit refresh over and over, sometimes it shows $_SESSION['username'] and sometimes it doesnt. It is seemily random. If anyone has any insight into what I'm doing wrong here, or suggestions to try out, it would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/85196-sessions-randomly-disappearingreappearing/ Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 Since you are using refresh, this may not be your problem, but sessions rely on the site name to be the same, as in, www.mysite.com is not the same as mysite.com So verify that you are in fact either using or not using www each time. Quote Link to comment https://forums.phpfreaks.com/topic/85196-sessions-randomly-disappearingreappearing/#findComment-434634 Share on other sites More sharing options...
brianmuse Posted January 9, 2008 Author Share Posted January 9, 2008 There is a www everytime. I did not know that it mattered, though Quote Link to comment https://forums.phpfreaks.com/topic/85196-sessions-randomly-disappearingreappearing/#findComment-434639 Share on other sites More sharing options...
brianmuse Posted January 9, 2008 Author Share Posted January 9, 2008 Here's a curveball: I can't recreate the problem in Firefox. It only seems to occur in IE Quote Link to comment https://forums.phpfreaks.com/topic/85196-sessions-randomly-disappearingreappearing/#findComment-434703 Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 Probably a cookie issue then, since sessions are written as a temp cookie. Quote Link to comment https://forums.phpfreaks.com/topic/85196-sessions-randomly-disappearingreappearing/#findComment-434726 Share on other sites More sharing options...
brianmuse Posted January 9, 2008 Author Share Posted January 9, 2008 Probably a cookie issue then, since sessions are written as a temp cookie. could you elaborate? Also, would this explain somehow why when refreshing many times the session variables would disappear and return again? Quote Link to comment https://forums.phpfreaks.com/topic/85196-sessions-randomly-disappearingreappearing/#findComment-434728 Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 Nope, just throwing out ideas for you. Quote Link to comment https://forums.phpfreaks.com/topic/85196-sessions-randomly-disappearingreappearing/#findComment-434734 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.