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

【PHP】网页安全认证

PHP中文网
PHP中文网Original
2016-05-25 17:15:581534browse

【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)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn