musclehead Posted November 20, 2008 Share Posted November 20, 2008 I have a bizzare session problem that I can't seem to figure out. I've used sessions a great deal in the past, and this is absolutely baffling me! I'm doing some very simple checks against a session variable to either alert the user or not. For some weird reason, when I refresh the page, the session variable is no longer set. I can't figure out why - it's simple enough. If the variable in the script itself is greater than the session variable (or if the session variable is not set at all), set the session variable and move on. On the reload of the script, if the original alert value has not incremented, nothing should happen. If it HAS gotten bigger, it should reset the session variable with the new value. <? session_start(); $alert = 0; while (...some condition...){ $alert += 1; } if (($alert > $_SESSION['alert']) || !isset($_SESSION['alert'])){ echo "<script>alert('something');</script>"; $_SESSION['alert'] = $alert; } ?> What am I missing?!?!?! Quote Link to comment https://forums.phpfreaks.com/topic/133527-solved-php-session-variables/ Share on other sites More sharing options...
premiso Posted November 20, 2008 Share Posted November 20, 2008 <?php session_start(); // Check/set variables. if (isset($_SESSION['alert'])) { $alert = $_SESSION['alert']; }else { $alert = 0; $_SESSION['alert'] = 0; } $x=5; while ($alert < $x){ $alert++; } // should set $alert equaled to after the while loop // since we put isset up top remove it from here as the session variable should be set now. if (($alert > $_SESSION['alert']) ){ $_SESSION['alert'] = ($alert + 1); // add 1 to the alert echo "<script>alert('" . $_SESSION['alert'] . "');</script>"; } ?> Give that a try and see what comes of it. Quote Link to comment https://forums.phpfreaks.com/topic/133527-solved-php-session-variables/#findComment-694641 Share on other sites More sharing options...
musclehead Posted November 25, 2008 Author Share Posted November 25, 2008 Sorry for the delay in responding - problem had nothing to do w/ the code - permissions were not set correctly to instantiate a session in the first place, thus everything was getting lost. All is good now - thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/133527-solved-php-session-variables/#findComment-698891 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.