<?php
$username = $_POST['username'];
$password = $_POST['password'];
if (strlen($username) ==0 || strlen($password) == 0) {
echo "用户名和密码不能为空,<a href='login.htm'>点击</a>重新输入";
}else{
$link = mysqli_connect('localhost','root','','dis');
if(!$link) die("数据库连接失败");
$sql = "SELECT * FROM user WHERE username='{$username}' AND password='$password'";
$result = mysqli_query($link, $sql);
if(!$result) die("数据库查询错误".$sql);
$rows = mysqli_num_rows($result);
if ($rows == 1) {
$user = mysqli_fetch_array($result, MYSQLI_ASSOC);
// var_dump($user);
$uid = $user['uid'];
setcookie('login',1,time()+60*60);
setcookie('username', $username, time()+60*10);
setcookie('uid',$uid,time()+60*60);
header("Location:index.php");
}else{
echo "用户名与密码匹配,请重新输入";
}
}
?>
这是登陆的php,我不太懂这一部分
if ($rows == 1) {
$user = mysqli_fetch_array($result, MYSQLI_ASSOC);
// var_dump($user);
$uid = $user['uid'];
setcookie('login',1,time()+60*60);
setcookie('username', $username, time()+60*10);
setcookie('uid',$uid,time()+60*60);}
这段代码是怎么将密码和用户对应起来,密码不对是怎么验证出来的呢?
求助~~~TAT
蟹蟹
我是新手_请多指教