Simplest PHP login

If you want to restrict access to a directory, then think .htaccess and http authentication.
This is a solution when http authentication is not an option or if you want to restrict access to a single php script file.
It emulates regular http authentication with all the power & flexibility you get from php.
<?php $username = 'admin'; $password = 'pass'; if ( !isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] != $username || $_SERVER['PHP_AUTH_PW'] != $password ) { Header("WWW-Authenticate: Basic realm=\"My Protected Page\""); Header("HTTP/1.0 401 Unauthorized"); echo '<html><body> <h1>Rejected!</h1> <big>Wrong Username or Password!</big> </body></html>'; exit; } ?>