0

popup dialog is there but entering any credentials - the page is available
what is the problem ?

if(!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !$_SERVER['PHP_AUTH_USER'] == 'lorem' || !$_SERVER['PHP_AUTH_PW'] == 'ipsum'){
    header('http/1.1 401 Unauthorized');
    header('WWW-Authenticate: Basic realm="Wonder Penguin"');
    die("Access Denied !");
}
qadenza
  • 9,025
  • 18
  • 73
  • 126
  • Checkout [https://stackoverflow.com/questions/14724127/why-are-serverphp-auth-user-and-serverphp-auth-pw-not-set](https://stackoverflow.com/questions/14724127/why-are-serverphp-auth-user-and-serverphp-auth-pw-not-set) – Hritik R Sep 02 '21 at 04:31
  • @HritikR - I have no problem with setting variables, but with their values. Otherwise the popup form would not be present – qadenza Sep 02 '21 at 04:46
  • 1
    `!$_SERVER['PHP_AUTH_USER'] == 'lorem'` is wrong, you want `$_SERVER['PHP_AUTH_USER'] != 'lorem'` there. (Or you would have to use an additional set of braces there, `!($_SERVER['PHP_AUTH_USER'] == 'lorem')`) – CBroe Sep 02 '21 at 08:11
  • @CBroe - it works thanks a lot, you could write the answer – qadenza Sep 02 '21 at 09:16

1 Answers1

1

!$_SERVER['PHP_AUTH_USER'] == 'lorem' is wrong, you want
$_SERVER['PHP_AUTH_USER'] != 'lorem' there.

Or you would have to use an additional set of braces there, !($_SERVER['PHP_AUTH_USER'] == 'lorem')

The reason is operator precedence.

CBroe
  • 91,630
  • 14
  • 92
  • 150