PHP检测账号密码是否匹配:
HTML代码:
#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;}
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)
})
}
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 "";
}
}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 "密码错误";
}
}
}