leisnerr Posted March 19, 2007 Share Posted March 19, 2007 Hi again, was trying to learn how to create and erase session's today. The code I came up with was this, my problem is that I thought it would be incrementing by 1 each time I refreshed the page, any tips? <?php session_start(); if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1; else $_SESSION['views']=1; echo "Views=". $_SESSION['views']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/43354-session-question/ Share on other sites More sharing options...
per1os Posted March 19, 2007 Share Posted March 19, 2007 <?php session_start(); echo "Views=". $_SESSION['views']; // echo this first to make sure there is a variable if(isset($_SESSION['views'])) $_SESSION['views']++; else $_SESSION['views']=1; echo "ViewsNow=". $_SESSION['views']; // see if it incremented ?> The above should work, your old code should also work. Try this see what happens Quote Link to comment https://forums.phpfreaks.com/topic/43354-session-question/#findComment-210542 Share on other sites More sharing options...
leisnerr Posted March 19, 2007 Author Share Posted March 19, 2007 Okay I got it now. I'm a little confused on the isset command though if you could gimme a quick breifing on it. They didn't really explain it's purpose or what it primarily is defining, is it to check for what the variable $_SESSION['views'] actual value is? Or just to check if the function has been properly executed? Still a little confused on session's but what you said helped and I got mine working correctly now so thanks in advance. :-) Quote Link to comment https://forums.phpfreaks.com/topic/43354-session-question/#findComment-210565 Share on other sites More sharing options...
per1os Posted March 19, 2007 Share Posted March 19, 2007 If a variable isset (meaning it has been defined) than it returns true. If that variable has not been set or defined it returns false. <?php $cat = "fly"; if (isset($cat)) { print $cat . " has been set"; } if (isset($someVar)) { print $someVar . " has also been set"; }else { print "someVar was not set!!!"; } ?> Works for array indexes also, which is what you are doing with session, checking if an index of an array has been set/defined. Quote Link to comment https://forums.phpfreaks.com/topic/43354-session-question/#findComment-210569 Share on other sites More sharing options...
wildteen88 Posted March 19, 2007 Share Posted March 19, 2007 isset checks to see whether the variable exists or not. It does not check the variables value. Umm, frost beat me \0/ Quote Link to comment https://forums.phpfreaks.com/topic/43354-session-question/#findComment-210570 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.