纯php登录验证demo



<!-- html -->


1
<!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8" /> 5 <title>Document</title> 6 </head> 7 <body> 8 <form action="check.php" method="post"> 9 <p> 10 <input type="text" name="username" value="用户名"> 11 </p> 12 <p> 13 <input type="password" name="pwd" value="密码" placeholder="密码"> 14 </p> 15 <p> 16 <input type="submit"> 17 </p> 18 </form> 19 </body> 20 </html>
 
 

<!-- php -->

 1 <?php
 2     $username = $_POST['username'];
 3     $password = $_POST['pwd'];
 4 
 5     $link = mysqli_connect('localhost:3308', 'root', '123456', 'mytest1');
 6     mysqli_set_charset($link, 'utf8');
 7 
 8     $result = mysqli_query($link, "SELECT * FROM userinfo WHERE username='{$username}' AND password='{$password}'");
 9     $num = mysqli_num_rows($result); // 通过result的长度(数量0or1) 来判断是否有查到数据
10         // print_r($result);
11     $row = mysqli_fetch_array($result); //fetch数据,以便查找需要的具体信息
12     if($num == 1){
13         echo "您已经成功登陆,";
14         echo ($row['isvip'])?'我们敬爱的会员!': '你好!';
15     }else {
16         print_r('用户名或密码错误');
17     }
18 ?>

猜你喜欢

转载自www.cnblogs.com/vaso-me/p/11223634.html