首页 >php教程 >PHP源码 >【PHP】网页安全认证

【PHP】网页安全认证

PHP中文网
PHP中文网原创
2016-05-25 17:15:581533浏览

【PHP】网页安全认证

<?php
   function authenticate_user() {
      header(&#39;WWW-Authenticate: Basic realm="Secret Stash"&#39;);
      header("HTTP/1.0 401 Unauthorized");
      exit;
   }

   if (! isset($_SERVER[&#39;PHP_AUTH_USER&#39;])) {
      authenticate_user();
   } else {
      mysql_pconnect("localhost","authenticator","secret") or die("Can&#39;t connect to database server!");
      mysql_select_db("java2s") or die("Can&#39;t select authentication database!");

      $query = "SELECT username, pswd FROM user WHERE username=&#39;$_SERVER[PHP_AUTH_USER]&#39; 
      AND pswd=MD5(&#39;$_SERVER[PHP_AUTH_PW]&#39;)";

      $result = mysql_query($query);

      // If nothing was found, reprompt the user for the login information.
      if (mysql_num_rows($result) == 0) {
         authenticate_user();
      }
   }
?>

                   

 以上就是【PHP】网页安全认证的内容,更多相关内容请关注PHP中文网(www.php.cn)!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn