moogal Posted August 18, 2008 Share Posted August 18, 2008 Hi, I'm having a bizarre problem with a project I'm working on. Basically, on completion of certain functions I need to display a message to the user on the next page they visit, so I have a function which sets a session variable with the message text. Then, on page load, there is another function which checks if this has been set, and if so displays the message and unsets the session variable. The problem I'm having is that on some pages, despite the session variable being unset, the message keeps appearing until I log out/clear the session completely. I've tried dumping the session and the variable is definitely being unset in the right place. I have no idea why this should be happening, and Googling didn't turn up anything useful. Has anyone encountered anything similar to this, and if so - any tips for solving it? Thanks in advance (from me and my sanity!) A (simplified) example of the code in question: function flash($strMessage) { $_SESSION['message'] = $strMessage; } function showFlash() { if(isset($_SESSION['message']) { echo "<div class='flash'>{$_SESSION['message']}</div>"; unset($_SESSION['message']); } } Quote Link to comment Share on other sites More sharing options...
revraz Posted August 18, 2008 Share Posted August 18, 2008 Without seeing code, we can only assume that the session is being set somewhere else as well. Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted August 18, 2008 Share Posted August 18, 2008 When, the going to the other pages is it being set anywhere else, and then not going through the unset process? We won't be able to help you with the code you provided, you would need to look through the code that it flows through to bring the message up. Quote Link to comment Share on other sites More sharing options...
moogal Posted August 18, 2008 Author Share Posted August 18, 2008 It couldn't really be set anywhere else. There's no specific path you have to follow to get the message to come up - the point of me putting it in the session was that I could then have it display on whichever page the user goes to next, so it's a bit difficult to post code as I have no way of controlling which page they then move on to. The only way that the variable is ever modified or accessed is via the two methods above. What I've just tried is putting a counter variable in, so that each time the message is set, the counter is incremented and displayed with the message. This worked as expected - the same counter value was displayed on every page until another page set a different message, which makes me think it's not being set on each subsequent page. I'm trying something else at this very moment - moving the variable into a class stored in the session just to see if that makes any difference. Quote Link to comment 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.