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);
//用用户名和暗码进行查询,若查到的记录正好为一条,则设置SESSION和COOKIE,同时进行页面重定向
if(mysqli_num_rows($data)==1){
$row = mysqli_fetch_array($data);
$_SESSION[""user_id""]=$row[""user_id""];
$_SESSION[""username""]=$row[""username""];
setcookie(""user_id"",$row[""user_id""],time()+(60*60*24*30));
setcookie(""username"",$row[""username""],time()+(60*60*24*30));
$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