亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PHP網(wǎng)頁(yè)安全認(rèn)證的實(shí)例詳解

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

PHP網(wǎng)頁(yè)安全認(rèn)證的實(shí)例詳解

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

<?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 "用戶驗(yàn)證!!";
  exit;
 } else {
  echo "驗(yàn)證通過";
  
  header("location:http://www.baidu.com");
  //unset($_SERVER['PHP_AUTH_USER']);  
 }
?>

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

<?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ǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論