0

我正在尝试创建一个自动注销系统,当页面处于非活动状态时会自动注销系统,我是新手,当我向登录页面添加代码时,我收到了这些警告

Warning: mysql_query() expects parameter 1 to be string, resource given in C:\xampp\htdocs\how are things\admin panel\login.php on line 80
Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\how are things\admin panel\login.php on line 81

第 80 行和第 81 行的代码分别如下

  if($no_rows > 0){
                         while($resGetAdmin = mysql_fetch_assoc($rs_user))

这是我添加的代码

    $rs_user= mysql_query($check_login);
                 $no_rows   = mysql_num_rows($rs_user);
                 if($no_rows > 0){
                         while($resGetAdmin = mysql_fetch_assoc($rs_user)){
                          $selQuery="select * from  login where  user_id=".$resGetAdmin['user_id'] ." AND loginDate ='$current_date'";
                          $rgetData= mysql_query($selQuery);
                          $num_login   = getSqlNumber($selQuery);
                          if($num_login==0) {
                          $insQuery= "insert into login (user_id,loginTime,loginDate,count)   values (".$resGetAdmin['user_id'].",'$current_time','$current_date',1)";
                          $login_user= mysql_query($insQuery);
                          $insert_id=mysql_insert_id();
                          $_SESSION['loginTime']=$current_time;
                           }else{
                               $count = mysql_result($rgetData,0,’count’);
                               $count = $count+1;
                               $updateQuery= "update login set loginTime='$current_time' ,loginDate='$current_date' , count ='$count' where user_id=".$resGetAdmin['user_id'] ." AND loginDate='$current_date'";
                               $login_user= mysql_query($updateQuery) or mysql_error();
                               $_SESSION['loginTime']=$current_time;
                                }

                              $_SESSION['user_id']=$resGetAdmin['user_id'];
                              header("Location: index.php");
                                   exit;
                                  }
                            }

这是我添加上面代码之前的原始登录页面

<?php
if(isset($_POST['submit'])){
     $username = $_POST['username'];
     $password =($_POST['password']);
     $hash_password = md5($password);
     $hash_password1 = sha1($hash_password);
     $hash_password2 = crypt($hash_password1,"st");
     $hash_password3 = hash("sha512",$hash_password2);

     $guess = $_POST['captcha'];
     $real = (isset($_SESSION['real'])) ? $_SESSION['real'] : "";
    if (empty($guess))
     { 
         die("Please enter the correct CAPTCHA.<br>");
     } 
if (!empty($guess) && $guess !== $real)
{
    die("Please enter the correct CAPTCHA.<br>");
}
     if(empty($username) or empty($password)){
         echo "<p>fields empty !</p>";
     }
     else {
          $check_login = mysql_query("SELECT id, type FROM users WHERE username='$username' AND password='$hash_password3'");
          if(mysql_num_rows($check_login) == 1) {
             $run = mysql_fetch_array($check_login);
             $user_id = $run['id'];
             $type = $run['type'];
             if($type == 'd'){
                  echo "<p> Your Account is deactivated byt the site admin!</p>";
             } else {
                  $_SESSION['user_id'] = $user_id;
                  header('location: index.php');
             }
          } else {
                  echo "<p> User Name or Password incorrect!</p>";

              }  }
}

?>

我将整个代码粘贴在登录页面上,但我离开了 timeout.php 页面,在此先感谢大家

4

2 回答 2

3

无需通过编写自己的代码来注销。每个会话可以配置为仅持续一段时间。您可以设置最大生命周期

于 2013-05-02T18:57:51.817 回答
0

我的赌注是:

第 80 行:

$rs_user= mysql_query($check_login);

$check_login不是包含查询的字符串
$rs_user因为查询失败而返回 false 。

(我的猜测是 $check_login 是另一个查询的结果集)

*警告:mysql_query() 期望参数 1 是字符串,资源在 C:\xampp\htdocs\how are things\admin panel\login.php 第 80 行*

第 81 行:

$no_rows   = mysql_num_rows($rs_user);

警告:mysql_num_rows() 期望参数 1 是资源,在第 81 行的 C:\xampp\htdocs\how are things\admin panel\login.php 中给出 null

(mysql说给出了NULL,这是因为$rs_user返回false(见上面第80行的解释)

于 2013-05-02T19:03:52.443 回答