chrischen Posted January 8, 2009 Share Posted January 8, 2009 So the user posts a comment and then the $_SESSION['post'] = 1; Then they are redirected to a new page and this code is executed: 1. if($_SESSION['post'] == 1) { //for some reason $_SESSION['post'] is 0 2. $notice .= 'Your comment has been posted!'; 3. echo '<div class="notice green">'.$notice.'</div>'; 4. $_SESSION['post'] = 0; // as long as this line is here post is always equal to 0 5. } However the weird problem is that $_SESSION['post'] is 0 in line one as long as long as line 4 is there. If I remove line 4 then $_SESSION['post'] is 1. However even if I have it equal 123 or another integer on line 4 $_SESSION['post'] still equals 0. Also if I have $_SESSION['post'] equal a string on the first page then it works fine and equals the string on the second page. So basically what's happening is the existence of the code on line four is overriding the value of $_SESSION['post'] to equal 0 as long as it was initially an integer value, even if line 4 is not set to equal 0 (tested line four with a string and it was still overrided to 0). Quote Link to comment https://forums.phpfreaks.com/topic/139965-solved-weird-session-problem/ Share on other sites More sharing options...
chrischen Posted January 8, 2009 Author Share Posted January 8, 2009 Nevermind i just solved it. When the user submits the comments the first time it loads the page again before redirecting and the code to set it to 0 is after the header(location: ) command. I guess php code after that is executed too? Well, I learn something new everyday. Quote Link to comment https://forums.phpfreaks.com/topic/139965-solved-weird-session-problem/#findComment-732305 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.