in this code
if ((array_key_exists("id", $_SESSION) AND $_SESSION['id']) OR (array_key_exists("id", $_COOKIE) AND $_COOKIE['id'])) {
header("Location: loggedPage.php");
}
I dont know different between them. Can someone explain it to me?
Thanks
Minh Phuc
array_key_exists(“id”, $_SESSION ) :
This lines checks whether id key exists in $_SESSION (Array) and returns true or false.
$_SESSION['id']) :
This lines returns the value of id in SESSION or returns NULL
array_key_exists()
checks whether or not a key exists in an array, not caring what value the key might carry. It might carry false, null, 0 and so on..
if($_SESSION['ID'])
returns the contents of the variable, after which it is cast as a boolean.
It is proven that isset()
is faster than array_key_exists()
. The only difference between the two is $key => null
will return false on isset()
and true on array_key_exists()