ShaolinF Posted October 17, 2007 Share Posted October 17, 2007 Hey Guys, What does the following code mean ? (!isset($_SESSION['LOGGEDIN'])== FALSE) { } Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/ Share on other sites More sharing options...
corbin Posted October 17, 2007 Share Posted October 17, 2007 !isset() would mean if the value passed to isset isn't set, and then the == false would mean if that condition before it is false... So that's like saying: if($_SESSION['LOGGEDIN'] IS NOT NOT SET) That is basically the same as: if(isset($_SESSION['LOGGEDIN'])) { } Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371876 Share on other sites More sharing options...
marcus Posted October 17, 2007 Share Posted October 17, 2007 Isn't that sort of a contradiction? If the session doesn't exist and equals the constant false... hmm. Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371878 Share on other sites More sharing options...
ShaolinF Posted October 17, 2007 Author Share Posted October 17, 2007 Thanks guys, I was working on some code and it was working fine and now randomly it doesnt want to work no more and Im having to go through all the code, argh! Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371889 Share on other sites More sharing options...
ShaolinF Posted October 17, 2007 Author Share Posted October 17, 2007 Well here is a piece of code which could be the cause of the problem. Please run through it and see if you can find any logical errors on the statements. <?php if (!isset($_SESSION['LOGGEDIN'])== FALSE) // If user is not logged in { //Add session //echo "session is not set! User is not logged in" . "<BR>"; $_SESSION['LOGGEDIN'] = TRUE; $_SESSION['NAME'] = $_POST['name']; $_SESSION['CONTACTNO'] = $_POST['contact']; $_SESSION['EMAILADD'] = $_POST['email']; $_SESSION['GENDER'] = $_POST['sex']; $_SESSION['TIME'] = date("D dS M,Y h:i a"); } else { echo "<BR>" . "session is set! User is logged in"; //grab data from cookies if needed } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371894 Share on other sites More sharing options...
corbin Posted October 17, 2007 Share Posted October 17, 2007 Actually I think I may have had an error with the way I interpretted that.... isset will return either true or false, and so saying !isset() == FALSE could mean if isset != false or it could mean if (isset() == false) == false Lemme check since I'm not sure.... What a weird syntax.... lol Not sure how PHP would interpret that. Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371896 Share on other sites More sharing options...
corbin Posted October 17, 2007 Share Posted October 17, 2007 $lol = 'hi'; if(!isset($lol) == false) echo 'hi'; With a quick test, that echo'd 'hi', so it appears my original interpretation was correct ;p.... That's the same as going if(isset($var)) The problem appears to lie with: if (!isset($_SESSION['LOGGEDIN'])== FALSE) // If user is not logged in That means if the session var isset, but the commenting seems to imply that it thinks that will be true if the session var is not set.... Try if(!isset($_SESSION['LOGGEDIN'])) { Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371899 Share on other sites More sharing options...
atlanta Posted October 17, 2007 Share Posted October 17, 2007 Yes corbin your right the statement should be if (!isset($_SESSION['LOGGEDIN'])) which means the user is not logged in because anytime you add ! in front it means the opposite of the answer that is going to be given back. so adding the == false would be a contradiction Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371903 Share on other sites More sharing options...
corbin Posted October 17, 2007 Share Posted October 17, 2007 I know.... I was just wondering in which order PHP would eval it... Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371905 Share on other sites More sharing options...
ShaolinF Posted October 17, 2007 Author Share Posted October 17, 2007 Your a life saver. I still quite new to php and tend to get confused. So in layman terms, would isset() mean whether any content in the $var exists ? !isset($var) // If there is nothing in var then .. isset(var) // if there is something in var do this .. correct ? Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371907 Share on other sites More sharing options...
corbin Posted October 17, 2007 Share Posted October 17, 2007 !function() is teh same thing as saying: function() == false isset will return false if the variable passed to it is/has either: -not been initialized -is equal to the php constant null -been run through unset() For example: $v = null; if(!isset($v)) echo 'not set'; if(!isset($nonexistant)) echo 'not set'; $v1 = 'hi'; unset($v1); if(!isset($v1)) echo 'not set'; //this would put out not setnot setnot set Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371913 Share on other sites More sharing options...
ShaolinF Posted October 17, 2007 Author Share Posted October 17, 2007 Thanks. <?php $refer=$_SERVER['HTTP_REFERER']; if($refer == ("http://www.mysite.co.uk/test/") || $refer == ("http://www.mysite.co.uk/test/index.htm") || $refer == ("http://www.mysite.co.uk/test/index.htm/")) { //echo "overwrite session"; $_SESSION['LOGGEDIN'] = FALSE; } else { //do nothing } ?> Can you see any problems with this ? Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371920 Share on other sites More sharing options...
corbin Posted October 17, 2007 Share Posted October 17, 2007 $_SESSION['LOGGEDIN'] = FALSE; I'm not quite sure why you're script would log a user out of they came from your site x.x The mysite.co.uk part has been replaced with your site right? It's bad practice to rely on referrer checks since they can be spoofed easily.... Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371926 Share on other sites More sharing options...
ShaolinF Posted October 17, 2007 Author Share Posted October 17, 2007 Well what happens is once someone submits a form they get directed to that page where they confirm their details. The point of the $refer statement is if the user re-submits a form, his new data will over right the old data. EDIT: mysite.co.uk is replaced with my website link. The false is checked by the IF statement which I started the thread with. Quote Link to comment https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371929 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.