if(!empty($user_username)&&!empty($user_password)){ //MySql中的SHA()函数用于对字符串进行单向加密 $query = "SELECT id, name FROM admin_user WHERE name = '$user_username' AND "."pass = SHA('$user_password')"; //用用户名和密码进行查询 $data = mysqli_query($dbc,$query); //若查到的记录正好为一条,则设置SESSION,同时进行页面重定向 if(mysqli_num_rows($data)==1){ $addlogin = "update admin_user set logincount = logincount+1 where name = '$user_username';"; $row = mysqli_fetch_array($data); $_SESSION['user_id']=$row['id']; $_SESSION['username']=$row['name']; mysqli_query($dbc,$addlogin); $home_url = 'index.php'; header('Location: '.$home_url); }else{//若查到的记录不对,则设置错误信息 $error_msg = $user_username.', Sorry, you must enter a valid username and password to log in.'; } }else{ $error_msg = $user_username.', Sorry, you must enter a valid username and password to log in.'; } } }else{//如果用户已经登录,则直接跳转到已经登录页面 $home_url = 'index.php'; header('Location: '.$home_url); } ?>