这篇文章主要介绍php如何检测账号密码是否匹配,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
PHP检测账号密码是否匹配:
推荐:php服务器
HTML代码:
<style> #login{width: 250px;height: 120px;background-color: aquamarine;position: fixed;top: 0px;left: 0px;right: 0px;bottom: 0px;margin: auto;padding:50px;text-align: left;} </style> <script type="text/javascript" src="__PUBLIC__/js/jquery-3.2.1.js"></script> <script type="text/javascript"> function rusername(obj){ var username=$(obj).val(); $.post("{:U('Login/lusername')}",{username:username},function(data) { $("#username").html(data) }) } function rpassword(obj){ var password=$(obj).val(); $.post("{:U('Login/lpassword')}",{username:password},function(data) { $("#password").html(data) }) } </script> <div id="login"> <form action="__ACTION__" method="post"> <p><input name="username" type="text" value="" size="25" placeholder="填写用户名" onblur="rusername(this);"/><br/><span id="username" style="font-size:12px;color:red;"></span></p> <p><input name="password" type="password" value="" size="25" placeholder="输入密码" onblur="rpassword(this);"/><br/><span id="password" style="font-size:12px;color:red;"></span></p> <p><input name="submit" type="submit" value="登录"/> <input name="submit" type="submit" value="注册"/> </p> </form> </div>
PHP代码:
<?php namespace Home\Controller; use Think\Controller; class LoginController extends Controller { public function login(){ if($_POST){ $where['username']=$_POST['username']; $where['password']=md5("php100".$_POST['password']); $users=M('users')->where($where)->select(); if($users){ $_SESSION['id']=$users['id']; $_SESSION['user_shell']=md5($users['username'].$users['password']); $this->redirect('Index/index'); }else{ echo "<script type='text/javascript'>alert('用户名或密码错误');window.history.go(-1);</script>"; } }else{ $this->display(); } } public function lusername(){ $where['username']=I('username'); $users=M('users')->where($where)->select(); if(!$users){ echo "用户名错误"; } } public function lpassword(){ $where['password']=I('password'); $users=M('users')->where($where)->select(); if(!$users){ echo "密码错误"; } } }
以上是php如何检测账号密码是否匹配的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。