首頁  >  文章  >  php教程  >  【PHP】网页安全认证

【PHP】网页安全认证

PHP中文网
PHP中文网原創
2016-05-25 17:15:581488瀏覽

【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