php 用户登录验证_php+ajax实现登录验证

login.js$(document).ready(function(){

//提交表单

$('#submit_btn').click(function(){

show_loading();

//var myReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; //邮件正则

if($('#account').val() == ''){

show_err_msg('账号还没填呢!');

$('#account').focus();

//}//else if(!myReg.test($('#email').val())){

//show_err_msg('您的邮箱格式错咯!');

//$('#email').focus();

}else if($('#password').val() == ''){

show_err_msg('密码还没填呢!');

$('#password').focus();

}else{

//show_msg('登录成功咯!  正在为您跳转...','shop.php');

postdata(); //button被点击时执行postdata函数

}

});

});

function postdata() {

$.ajax({

type: "post",

url: "check.php",

data:"&checkcode="+$("#j_captcha").val()+"&account="+$("#account").val()+"&pass="+$("#password").val(),

error: function(){

alert('Error loading php document');

},

success: function(data){

if (data == "success") {show_msg('登录成功咯!  正在为您跳转...','shop.php');}

else if(data == "codefalse"){

show_err_msg('验证码输入错误!');

$('#j_captcha').focus();

}else {show_err_msg('账号或密码错误!');}

}

});

}

账  号:

autocomplete="off">

密 码:

class="password form-control x319 in">

验证码:

 看不清,换一张 

 记住登陆账号!

class="btn btn-primary btn-lg"> 登 录&nbsp 

Copyright © 2015 - 2016 系统登陆

check.php<?php

include '../inc/db.php';

session_start();

$pc = strtolower(trim($_POST['checkcode']));

$sc = strtolower($_SESSION['code']);

if($pc=='' || $pc!=$sc){

//header('location:login.html');

echo 'codefalse';

}else{

$a = $_POST['account'];

$p = $_POST['pass'];

$pass = m($p,$a);

//$cuspass=query('customer','cuspassword',"cusaccount=$a");

$stmt = $db->prepare('select cuspassword,id from customer where cusaccount=? ');

$stmt->execute([$a]);

$rs = $stmt->fetchAll(3);

//echo '

';

//print_r( $rs);

//echo $rs[0][0];

//exit;

if($pass==$rs[0][0]){

$_SESSION['customer']=[$a,$rs[0][1]];

unset($_SESSION['code']);

//header('location:shop.php');

echo 'success';

}else{

//header('location:login.html');

echo 'false';

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值