加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

纯php登录验证demo

发布时间:2020-12-13 22:18:10 所属栏目:PHP教程 来源:网络整理
导读:!-- 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 in



<!-- 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 ?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读