php验证手机验证码过期,验证过期时间
~~~
//說明目前短信驗證碼發(fā)送成功 需要記錄具體的驗證碼到session。
//需要保證驗證碼有過期時間。關于過期時間 可以記錄當前發(fā)送驗證碼的時間以及具體的有效時間
$data=array(
'code'=>$code,
'time'=>time(),//指定當前的時間
'limit'=>3600,//表示具體的過期時間
);
session('telcode',$data);
~~~
~~~
//判斷驗證碼是否過期
if($data['time']+$data['limit']
$this->ajaxReturn(array('status'=>0,'msg'=>'手機驗證碼過期'));
}
~~~
api對接
~~~
namespace Home\Controller;
use Think\Controller;
//公共控制器
class CommonController extends Controller {
public function __construct()
{
parent::__construct();
$this->getClientIp();
$this->checkFormId();
}
//檢查具體的請求的參數(shù)。如果參數(shù)解密出來并且跟明文是對應的 可以訪問。否則直接拒絕
public function checkFormId()
{
//或者具體的解密的字符串
$formid = I('get.formid');
if(!$formid){
//目前沒有傳遞具體的加密字符串
$this->ajaxReturn(array('status'=>0,'msg'=>'參數(shù)錯誤'));
}
$formid =authcode(base64_decode($formid),'DECODE');
if($formid!='pc'){
$this->ajaxReturn(array('status'=>0,'msg'=>'參數(shù)錯誤'));
}
}
//檢查具體請求者的IP來源
public function getClientIp()
{
//獲取請求者的IP地址
$ip = get_client_ip();
//定義具體容許訪問的IP地址 每一個值對應一個元素
$allow = array('127.0.0.1');
//根據(jù)請求的IP地址檢查是否可以訪問
if(!in_array($ip, $allow)){
$this->ajaxReturn(array('status'=>0,'msg'=>'沒有訪問權限'));
}
}
}
~~~
總結
以上是生活随笔為你收集整理的php验证手机验证码过期,验证过期时间的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 身份认证服务,PHP的HTTP身
- 下一篇: php用switch编写车费的输出,PH