Jun 16, 2008
Password Protection using WWW-Authenticate
This creates simple login function using the WWW-Authenticate header.
<?php // Define your username & password $username = 'admin'; $password = 'admin'; $login_successful = false; if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){ $usr = $_SERVER['PHP_AUTH_USER']; $pwd = $_SERVER['PHP_AUTH_PW']; if ($usr == $username && $pwd == $password){ $login_successful = true; } } if (!$login_successful){ header('WWW-Authenticate: Basic realm="Protected Area"'); header('HTTP/1.0 401 Unauthorized'); print "Login failed!\n"; exit(); } ?>


















No Comments, Comment or Ping
Reply to “Password Protection using WWW-Authenticate”