-3

I wrote a login script, but it doesn't work: In this script I can't log in

if($_SESSION['logged'] == TRUE){
echo "logged in";
}

if($_POST['pass'] == "blabla"){
$_SESSION['logged'] = TRUE;
}

if($_GET['logout']){
$_SESSION['logged'] = FALSE;
}
anon ymous
  • 39
  • 2
  • 10
  • You have several... undefined variables... I don't get it. What do you not understand? – Sverri M. Olsen Jan 28 '16 at 18:24
  • `===` and `==` are comparison operators and `=` is assignment operator. [http://php.net/manual/en/language.operators.php](http://php.net/manual/en/language.operators.php) – Rajdeep Paul Jan 28 '16 at 18:25
  • `=` is assignment, `==` is loose typed comparison, and `===` is strict typed comparison. Reading the [docs](http://php.net/manual/en/language.operators.comparison.php) is a good start. – Dave Chen Jan 28 '16 at 18:26
  • I have edited the code – anon ymous Jan 28 '16 at 18:35

2 Answers2

2

Your first two lines are a comparison:

$var1 === TRUE;
$var2 == TRUE;

You want them to be a declaration

$var1 = TRUE;
$var2 = TRUE;
0

This is not legal syntax for setting a variable

var1 === TRUE;

And nor is this

var2 == TRUE;

Use = to set a variable to a value.

The === and == are comparison tests not value assignments.

This is also not going to do a test

if($var1 = TRUE){echo "3";}

it will set $var1 to be true, ditto the other 2 times you try this line for $var2 and $var3

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149