Jump to content

Code help


ShaolinF

Recommended Posts

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

!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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.