<?phpheader('content-type:text/html;charset=utf-8');session_start();//获取输入的值$username=$_POST['username'];$password=$_POST['password'];//链接数据库$link=mysqli_connect('localhost','root','','test44');//字符集mysqli_set_charset($link,'utf8');//安全化$username=mysqli_real_escape_string($link,$username);//然后是sql语句$sql="select id from user2 where username='{$username}' and password='{$password}'";$result=mysqli_query($link,$sql);if($result&&mysqli_affected_rows($link)==1){$_SESSION['username']=$username;$_SESSION['islogin']=1;exit("<script>
alert('登录成功');
location.href='index.php';
</script>");}else{exit("<script>
alert('登录失败');
location.href='login.php';
</script>");}?>