I’m trying to compare a $_SESSION variable with a $_GET variable.
Both are numbers:
$_SESSION['auth'] === $_GET['user']
If both results equal to 1, then proceed.
For some reason, this is not working correctly. When using: if $_SESSION['auth'] = 2, and $_GET['user'] = 1, it still proceeds.
EDIT:
if(isset($_SESSION['auth'])===isset($_GET['user'])){
// proceeding code
}
With this, no matter what the $_GET variable resulted to, it still proceeds. Even if i tried the answer below with (int), it still gives me the same results.
I did try setting $_GET variable to some string to test, that doesn’t proceed because my $_SESSION variable is 1. It only proceeds through code with any number though.
Thanks
When you have a function inside a
if“equal-to” condition, you will be comparing with whatever that function returns.So in your case,
isset()returnstrueif the param is set, andfalseotherwise.That is what you’re comparing with, not the values.
It’s obvious you want check if the vars are set, before comparing. So do that first, and then begin your comparing. Like this: