I've summarized the crux of problem to be as brief as possible:
A simple script:
<?php
session_start();
$_SESSION['user']="logged";
then overwrite
$_SESSION['user']=0;
and show $_SESSION contents
var_dump($_SESSION);
shows $_SESSION['user'] is '0' - sure since it's just been overwritten
BUT now watch
if ($_SESSION['user']=="logged"){
echo "logged";
}
else{
echo "unlogged";
}
outputs "logged"....
Seems the change of variable type is only superficial - I've no idea what I'm doing wrong.. Do I need to use the === comparison to include checking the type?
Exactly, you need to do strict comparison ===
That is because PHP try convert your string in a number so "logged" pass to be 0
and then 0 == 0
http://www.php.net/manual/en/language.types.type-juggling.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With