Jump to content

Recommended Posts

!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'])) {

 

}

Link to comment
https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371876
Share on other sites

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
			}
?>

Link to comment
https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371894
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371896
Share on other sites

$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'])) {

Link to comment
https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371899
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371903
Share on other sites

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 ?

Link to comment
https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371907
Share on other sites

!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

Link to comment
https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371913
Share on other sites

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 ?

Link to comment
https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371920
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/73703-code-help/#findComment-371929
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.