<?php
header('content-type:text/html;charset=utf-8');
include 'connection.php';
//header('content-type:text/html;charset=utf-8');
$username = isset($_POST['username'])?$_POST['username']:"";
$password = isset($_POST['password'])?$_POST['password']:"";
$username = trim($username);
$password = trim($password);
if($username==""||$password=="")
{
echo "<script>alert('用户名或密码为空,请重新输入!');history.back();</script>";
}
else{
$password = md5($password);
$query = "select * from user where name_user=$username;";
$result = mysqli_query($link, $query);
if($result&&mysqli_num_rows($result))
{
$data = mysqli_fetch_assoc($result);
if($password==$data['password_user'])
{
setcookie("username",$username,time()+60*60*24);
setcookie("password",$password,time()+60*60*10);
mysqli_close($link);
header("location:view.php");
}
else
{
//echo "<script>alert('密码错误,请重新输入密码!');history.back();</script>";
echo "<script>alert('用户名不存在,请去注册!');</script>";
header("location:sign.php");/////////这里出了一点问题,执行了跳转,但是前面的警告框没有效果
}
}
else
{
echo "<script>alert('用户名不存在,请去注册!');location.href='sign.php';</script>";
}
}
?>