返回顶部

收藏

基于文件的网页身份认证

更多
<?php
   $authorized = FALSE;

   if (isset($_SERVER[\'PHP_AUTH_USER\']) && isset($_SERVER[\'PHP_AUTH_PW\'])) {
      $authFile = file(\"./password.txt\");

      foreach ($authFile as $login) {
         list($username, $password) = explode(\":\", $login);
         $password = trim($password);
         if (($username == $_SERVER[\'PHP_AUTH_USER\']) && ($password == md5($_SERVER[\'PHP_AUTH_PW\']))) {
            $authorized = TRUE;
            break;
         }
      }
   }

   // If not authorized, display authentication prompt or 401 error
   if (! $authorized) {
      header(\'WWW-Authenticate: Basic Realm=\"Secret Stash\"\');
      header(\'HTTP/1.0 401 Unauthorized\');
      print(\'You must provide the proper credentials!\');
      exit;
   }

?>

<!-- 
password.txt
joe:60d99e58d66a5e0f4f89ec3ddd1d9a80
-->
//该片段来自于http://outofmemory.cn

标签:php,安全

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2014-07-08 19:36:49aes 加密类 by 南宫傲
  2. 2014-07-17 19:24:53从360提供的PHP防SQL注入代码改成的一个类 by loking
  3. 2014-07-25 15:45:41php-md5变换算法之密文分割MD5 by 梁方
  4. 2014-07-25 20:41:09产生任意长度的字符串+数字随机数 by 傅小黑
  5. 2014-10-07 20:41:45php防止页面刷新代码 by loking
  6. 2014-11-22 15:21:26XSS安全过滤 by lihuibng
  7. 2014-11-25 14:14:15检验登陆类 by Flio
  8. 2014-07-14 20:01:15php 图片地址处理 by Linland
  9. 2014-07-18 20:05:42检查字符串中是否有外链 by 杨德伟
  10. 2014-07-26 15:01:56遍历树的方法二 by Flio
  11. 2014-07-26 19:45:59php可以逆转的加密类 by 南宫傲

发表评论