Posted By

asifjavedall on 01/21/11


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Desoxena
nickian
guillermoj88gmailcom


secure admin area


 / Published in: PHP
 

put this code in top index file. require_once('auth.inc.php');

  1. <?php
  2. //auth.inc.php
  3. if (isset($_SESSION['newlogin'])) {
  4. unset($_SESSION['newlogin']);
  5. unset($_SESSION['loggedout']);
  6. };
  7. $valid_passwords = array ("phil" => "nitelite2k10!!!!!!!!!!");
  8. $valid_apasswords = array ("admin" => "onefunction2k10!!!!!!!!!!");
  9. $valid_users = array_keys($valid_passwords);
  10. $valid_admin = array_keys($valid_apasswords);
  11.  
  12. $user = $_SERVER['PHP_AUTH_USER'];
  13. $pass = $_SERVER['PHP_AUTH_PW'];
  14.  
  15. $avalidated = (in_array($user, $valid_admin)) && ($pass == $valid_apasswords[$user]);
  16. $uvalidated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
  17. $validated = (($uvalidated == true) || ($avalidated == true)) ;
  18.  
  19. if (!$validated || isset($_SESSION['loggedout'])) {
  20. $_SESSION['newlogin'] = true;
  21. header('WWW-Authenticate: Basic realm="Login Area"');
  22. header('HTTP/1.0 401 Unauthorized');
  23. ?>
  24. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  25. <html xmlns="http://www.w3.org/1999/xhtml">
  26. <head>
  27. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  28. <title>Auth Screen</title>
  29. </head>
  30.  
  31. <body>
  32. <div id="messagebox">Authorisation Required.</div>
  33. </body>
  34. </html>
  35. <?php
  36. };
  37.  
  38. ?>

Report this snippet  

You need to login to post a comment.