欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP網(wǎng)頁安全認證的實例詳解

 更新時間:2017年09月28日 14:17:24   作者:callie  
這篇文章主要介紹了PHP網(wǎng)頁安全認證的實例詳解的相關(guān)資料,這里提供了兩種實現(xiàn)方法,一種基于數(shù)據(jù)庫另一種不基于數(shù)據(jù)庫的方法,希望通過本能幫助到大家,需要的朋友可以參考下

PHP網(wǎng)頁安全認證的實例詳解

 不基于數(shù)據(jù)庫:

<?php
    //unset($_SERVER['PHP_AUTH_USER']);
    $strAuthUser= $_SERVER['PHP_AUTH_USER'];      
    $strAuthPass= $_SERVER['PHP_AUTH_PW'];

 if (! ($strAuthUser == "a" && $strAuthPass == "a")) {
  header('WWW-Authenticate: Basic realm="wly"');
  header('HTTP/1.0 401 Unauthorized');
  echo "用戶驗證!!";
  exit;
 } else {
  echo "驗證通過";
  
  header("location:http://www.baidu.com");
  //unset($_SERVER['PHP_AUTH_USER']);  
 }
?>

基于數(shù)據(jù)庫:

<?php
  function authenticate_user() {
    header('WWW-Authenticate: Basic realm="Secret Stash"');
   header("HTTP/1.0 401 Unauthorized");
    exit;
  }
 
  if (! isset($_SERVER['PHP_AUTH_USER'])) {
    authenticate_user();
  } else {
    mysql_pconnect("localhost","authenticator","secret") or die("Can't connect to database server!");
    mysql_select_db("java2s") or die("Can't select authentication database!");
 
   $query = "SELECT username, pswd FROM user WHERE username='$_SERVER[PHP_AUTH_USER]' AND pswd=MD5('$_SERVER[PHP_AUTH_PW]')";
 
    $result = mysql_query($query);
 
    // If nothing was found, reprompt the user for the login information.
    if (mysql_num_rows($result) == 0) {
     authenticate_user();
    }
  }
 ?>

如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論