Reputation: 653
When I use the || (OR) operator in my if statement below I end up in an endless loop.
For sake of simplicity here is the var_dump:
$auth "0"
$id "2"
$enabled "1"
$page "auth-login.php"
If the criteria below is not met in the if statement then it will forward the user to auth-login.php (this is not applicable if the current $page is auth-login.php and auth-login-validate.php).
Statement without || (OR) operator: Forwards to auth-login.php as intended, but must also include auth-login-validate.php
if ($auth == '0' && $id != '1' && $enabled == '1' && $page != 'auth-login.php') {
header('Refresh: 0; URL=auth-login.php');
die();
}
Statement with || (OR) operator: Forwards to auth-login.php endlessly in a loop.
if ($auth == '0' && $id != '1' && $enabled == '1' && $page != 'auth-login.php' || $auth == '0' && $id != '1' && $enabled == '1' && $page != 'auth-login-validate.php') {
header('Refresh: 0; URL=auth-login.php');
die();
}
Upvotes: 0
Views: 46
Reputation: 148
Will be some precedence related error. Make sure to put the parentheses where you intend to encapsulate the "OR" parts
Upvotes: 1