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

【PHP】网页安全认证

PHP中文网
Release: 2016-05-25 17:15:58
Original
1541 people have browsed it

【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();
      }
   }
?>
Copy after login

                   

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template