Advertisement
w3tools_info

HTTP authentication via PHP

Sep 24th, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. <?php
  2. // Http authentication code by w3tools.info
  3. $user = "myuser"; //username here
  4. $pass = "mypass"; //password here
  5. if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER']!=$user || $_SERVER['PHP_AUTH_PW']!=$pass){
  6.     header('WWW-Authenticate: Basic realm="Enter password to access this page."');
  7.     header('HTTP/1.0 401 Unauthorized');
  8.     echo"You must be logged in";
  9.     exit;
  10. }
  11. # Your protected contents go here !!
  12. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement