if(!empty($user_username)&&!empty($user_password)){ //MySql中的SHA()函数用于对字符串进行单向加密 $query = "SELECT user_id, username FROM mismatch_user WHERE username = '$user_username' AND "."password = SHA('$user_password')"; //用用户名和密码进行查询 $data = mysqli_query($dbc,$query); //若查到的记录正好为一条,则设置COOKIE,同时进行页面重定向 if(mysqli_num_rows($data)==1){ $row = mysqli_fetch_array($data); setcookie('user_id',$row['user_id']); setcookie('username',$row['username']); $home_url = 'loged.php'; header('Location: '.$home_url); }else{//若查到的记录不对,则设置错误信息 $error_msg = 'Sorry, you must enter a valid username and password to log in.'; } }else{ $error_msg = 'Sorry, you must enter a valid username and password to log in.'; } } }else{//如果用户已经登录,则直接跳转到已经登录页面 $home_url = 'loged.php'; header('Location: '.$home_url); } ?>
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn