Reputation: 49
i'm trying to check if a session exist and has a specific value (2) to show a part of the website and if not it should return you to a other page.
So far i got this:
$_SESSION["deel"] = "2"; //set session deel to 2
$result = array("error" => false, "html" => null);
$result["error"] = false;
$result["html"] = "<h3>Session information:";
$result["html"] .= "<a href='/shop/?,69'>$_SESSION[class2C]</a>";
$result["html"] .= "</h3>";
after that we go to a other page:
if (!isset($_SESSION['deel']) || $_SESSION['deel'] == '2')
{ show the shit }
else
{ redirect }
However, it doesn't do anything and just shows me "the shit"
what am i doing wrong here?
Thanks in advance.
Upvotes: 0
Views: 331
Reputation: 46900
Your condition is wrong
if (!isset($_SESSION['deel']) || $_SESSION['deel'] == '2')
^ ^^
Means if the session is not set or if it is set then the value is 2, This will be true even if there is no session. You should do:
if (isset($_SESSION['deel']) && $_SESSION['deel'] == 2)
This can also be derived from your own statement
i'm trying to check if a session exist and has a specific value (2)
^ ^ ^
if (isset($_SESSION['deel']) && $_SESSION['deel'] == 2)
Upvotes: 2