dateDiff("$Setime","s"); if($diff>=10){//判断是否过期 $Setime=$Date->dateAdd($number "/> dateDiff("$Setime","s"); if($diff>=10){//判断是否过期 $Setime=$Date->dateAdd($number ">

Home  >  Article  >  Backend Development  >  session-Thinkphp框架下验证码问题

session-Thinkphp框架下验证码问题

WBOY
WBOYOriginal
2016-06-02 11:29:421074browse

框架session验证码php

public function myses(){
import("ORG.Util.Date");
$Setime=session('time');
$Date=new Date;
if($Setime!=NULL){
$diff=$Date->dateDiff("$Setime","s");
if($diff>=10){//判断是否过期
$Setime=$Date->dateAdd($number = 10, $interval = "s");//设置过期时间
session('time',$Setime);//将过期时间存在session里面
session('rand',rand(11111,99999));
echo session('rand');
echo 1111;//session存在,但是时间超过3分钟,重新生成验证码
}
else{
echo $diff;echo "
";
echo session('time'); echo "
";
echo session('rand'); echo "
";

echo 2222;//3分钟内再次获取输出该标示
}
}
else {
$Setime=$Date->dateAdd($number = 10, $interval = "s");//设置过期时间
session('time',$Setime);//将过期时间存在session里面
session('rand',rand(11111,99999));
echo session('rand'); echo "
";
echo session('time'); echo "
";
echo 3333;//session值没有被设置,生成新的验证码
}
}

<code></code>

逻辑应该没有错误,不知道是哪个用法不对,由于对session不熟悉,想这样通过在session中存一个过期时间,如果过期则重新生成。1、帮忙把以上代码改通,2、有更好实现该功能的方法也可以

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn