xsmscb 发表于 2017-4-5 12:23:45

php-用户和密码自动验证(只需将此文件放在输出前即可)

  只需将此文件放在PHP文件第一行即可,转载请注明网址 http://deepfuture.iteye.com/blog/695972。
  <?php
 /*
  * 密码验证
  * 程序:刘兴
  * 时间:2010-6
  */
?>
<?php require_once("connDB.php");//引入数据库连接参数?>
<?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{
      $sql="select * from adminuser where name='$_SERVER' and pass='$_SERVER'";
   $result=mysql_query($sql) or die("SQL语句执行错误!!!!!");
   if (mysql_num_rows($result)==0){
       authenticate_user();   
   }
?>
页: [1]
查看完整版本: php-用户和密码自动验证(只需将此文件放在输出前即可)