No more nonsense. Directly on the code directly using the session to store SMS verification code, the app has been said to get not to register the time has been prompted empty back to think about it or use the cache bar on the code:
//Send Verification Code method Public functionSendsmscodeop () {require_once(Base_root_path. DS. ' Api/framework/function/sms.php '); require_once(Base_root_path. DS. ' Api/framework/function/common.php '); $sms=NewSMS (); $_code=Rand(100000, 999999); $_mobile=$_post[' Mobile ']; $_content= "Hundred City Network" Welcome to register Hundred City Network, your verification code is ".$_code; if(Empty($_mobile)){ $this->_message (Code_error, ' mobile phone number cannot be empty ')); }Else{ if(!ismobile ($_mobile)){ $this->_message (code_error, ' cell phone number format is wrong ')); }Else{ if($sms->sendsms ($_content,$_mobile)){ //$_session[' sms_code '] = $_code; $_session[' mobile ' = $_mobile;This step is written to the cache, because the server does not have Memcache installed, using the framework of the cache mechanism to store$cache= Cache::getinstance (C (' Cache.type ')); $code _info=Array(); $code _info[' last_access '] = Time(); $code _info[' sms_mobile '] =$_mobile; $code _info[' sms_mobile_code '] =$_code; $cache->set ($_mobile,$code _info); $this->_printjson (Code_success,Array("Success" =>1), ' SMS Verification code sent successfully '); }Else{ $this->_message (Code_error, ' Verification code send failed '); } } } }
/** * @param $mobile * @param $mobile _code * Verify that the verification code is correct*/ Private functionCheckcode ($mobile,$mobile _code){ $obj _cache= Cache::getinstance (C (' Cache.type ')); $obj=$obj _cache->get ($mobile); if(Empty($obj)){ return Array(' Error ' = ' You have not sent a verification code '); }Else{ if(!isset($obj[' last_access ']) | | ( Time()-$obj[' last_access ']) >180*1000){ return Array(' ERROR ' = ' Verification code has expired '); }Else{ if($mobile _code==$obj[' Sms_mobile_code '] &&$mobile==$obj[' Sms_mobile '] ){ return Array("Success" = ' Verify through '); }Else{ return Array(' ERROR ' = ' Verification Code wrong '); } } }}
PHP to the app to write SMS verification code using Memcache cache verification code