短信验证码怎么一直提示超时,用的php setcookie+ajax

shxx12 2015-06-27 09:53:31
<?php
define('FUYUESOFT', true);

require(dirname(__FILE__) . '/include/init.php');


/* 获取meta和title信息 */
$smarty->assign('page_title', "找回密码|".$webConfig['web_name']);
$smarty->assign('keywords', $webConfig['web_keyword']);
$smarty->assign('description', $webConfig['web_description']);

//ajax重发短信
if (!empty($_GET['reSend'])){
$mobile = $_GET['mobile'];
$yzm = mt_rand(100000,999999);
$content = "您的验证码是{$yzm}。请在页面中提交验证码完成验证。【晋汇】";
//$content = iconv("utf-8","gbk",$content);

setcookie('yzm', $yzm, time()+65);
//发送短信
$url = "http://api.sms.cn/mt/?uid={$msgConfig['uid']}&pwd={$msgConfig['pwd']}&mobile={$mobile}&mobileids=&content={$content}&encode=utf8";
$send = file_get_contents($url);
//$send = file_get_contents("http://api.sms.cn/mt/?uid={$msgConfig['uid']}&pwd={$msgConfig['pwd']}&mobile={$mobile}&mobileids=&content={$content}&encode=utf8");
//echo $url;
echo 1;
exit;
}

//ajax验证正确性
if (!empty($_GET['yanzheng'])){
$yzm = intval($_GET['yzm']);
$true_yzm = intval($_COOKIE['yzm']);
if (empty($true_yzm)){
echo 0;
exit;
}
if ($true_yzm != $yzm){
echo 8;
exit;
} else {
echo 1;
exit;
}
exit;
}

if (!empty($_GET['step'])){
//提交登录
$mobile = trim($_POST['mobile']);
$step = trim($_GET['step']);

if ($step=="1"){
//找回密码第一步

if (empty($mobile)){
echo "<script>alert('error!');history.go(-1);</script>";
exit;
}

//判断该手机是否存在
$query = $dou->select($dou->table('user'), '*', " `mobile` = '{$mobile}' ");

$userInfo = $dou->fetch_array($query);
if (empty($userInfo)){
echo "<script>alert('该手机没有注册,请检查,如果没有注册请先注册!');history.go(-1);</script>";
exit;
}

$yzm = mt_rand(100000,999999);
$content = "您的验证码是{$yzm}。请在页面中提交验证码完成验证。【晋汇】";
//$content = iconv("utf-8","gbk",$content);

setcookie('yzm', $yzm, time()+65);
//发送短信
$send = file_get_contents("http://api.sms.cn/mt/?uid={$msgConfig['uid']}&pwd={$msgConfig['pwd']}&mobile={$mobile}&mobileids=&content={$content}&encode=utf8");

$smarty->assign('mobile', $mobile);
$smarty->display('findPwd_1.html');
exit;
}
if ($step=="2"){
//找回密码第二步
$mobile = trim($_GET['mobile']);

$smarty->assign('mobile', $mobile);
$smarty->display('findPwd_2.html');
exit;
}

if ($step=="3"){
//找回密码第三步 保存数据

$mobile = trim($_POST['mobile']);
$psw = md5(trim($_POST['password']));

$sql = "UPDATE " . $dou->table('user') . " SET psw = '{$psw}' WHERE mobile = '{$mobile}'";
$dou->query($sql);

/*$title = "[系统消息]密码重置通知";
$sql = "INSERT INTO " . $dou->table('message') . " (`title`, `content`, `uid`, `send_time`)" .
" VALUES ('$title', '$content', '$uid', '$time')";
$dou->query($sql);*/

echo "<script>alert('恭喜找回密码成功,前往登录!');location.href='login.php';</script>";
exit;

}
}

$smarty->display('findPwd.html');
?>


htm模板源码

{include file="head.html"}
<body>
<div id="web_bg" style="position:absolute; width:100%; height:100%; z-index:-1;top:0px">
<img style="position:fixed;" src="images/bg.jpg" height="100%" width="100%" />
</div>
<div class="width-all">
<div class="h3 title_3">找回密码</div>
</div>
<hr />
<div class="login" style="margin-top:20%;">
<form action="findPwd/step_2.html" method="post">
<div class="title_4">短信验证码已发送到:<span id="mobile">{$mobile}</span></div>
<div class="form-group input-group-lg">
<input name="yzm" type="text" class="form-control pull-left" id="yzm" maxlength="6" placeholder="输入6位验证码" style="width:60%;">
<button class="form-control pull-right btn btn-default" style="width:30%;" type="button" disabled="disabled" id="showTime2" onClick="reSend();">60</button>
</div>
<div style="height:20px; clear:both"></div>
<div>
<button type="submit" class="btn btn-warning btn-lg width-all" onClick="return yz();">下一步</button>
</div>
<div style="clear:both"></div>
<div class="login_span" style="display:none">
<div class="pull-left"><a href="/login.html">已有帐号,现在登录?</a></div>
</div>
</form>
</div>

<!-- SlidesJS Required: Link to jQuery -->
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<!-- End SlidesJS Required -->

<script>
{literal}
function yz(){
var yzm = $("#yzm").val();
var mobile = $("#mobile").html();
if (yzm==''){
alert('请输入6位数的手机验证码!');
$("#yzm").focus();
return false;
}
$.ajax({
type:'post',
url:'/findPwd.html?yanzheng=1&yzm='+yzm+"&mobile="+mobile,
success:function(msg){
var status = parseInt(msg);
if (status==0){
alert('您输入的验证码已经超时,请点击重发!');
return;
}

if (status==8){

alert('验证码输入不正确,请重新输入!');

return;

}

if (status==1){

//验证通过
location.href='/findPwd/step_2.html?mobile='+mobile;

return;

}

return;

},

});

return false;

}



showTime2();

function showTime2(){

var _time = $("#showTime2").html();

_time = parseInt(_time);

if (_time<1){

//跳转到答题界面

$("#showTime2").removeAttr("disabled").html('重发');

}else{

var num = _time - 1;

$("#showTime2").html(num);

setTimeout("showTime2()",1000);

}

}



/////////////////////////

function reSend(){
var mobile = $("#mobile").html();
var val = $("#showTime2").html();

if (val != '重发'){

return;

}

$.ajax({

type:'post',

url:'/findPwd.html?reSend=1&mobile='+mobile,

success:function(msg){

//alert(msg);

alert('重发成功,请查收短信!');

$("#showTime2").html("60").attr('disabled','disabled');

showTime2();

return;

},

});

}



{/literal}

</script>

<!-- End SlidesJS Required -->



</body>

</html>

...全文
485 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
shxx12 2015-07-01
  • 打赏
  • 举报
回复
to lirenbing008 不会调试啊
lirenbing008 2015-06-29
  • 打赏
  • 举报
回复
打印cookie 这种东西 一步一步调试就好了

4,251

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧