Two Verification code verification implementation , a direct in the form form Submission button implementation verification, a use of Ajax pass parameters to achieve validation:
1, directly on the form form Submit button implementation verification, in the controller VerifyController.class.php write the following code:
namespace Home\controller;
Use Think\controller;
Class Verifycontroller extends Controller {public
function index () {
$this->display ();
}
Public Function Checklogin () {
$verify =new \think\verify ();
$code =i (' post.verify ');//form Authentication Code
if ($verify->check ($code)) {
$this->success (' Authenticode correct ');
} else{
$this->error (' Authentication code error ');
}
Public Function Verify ()
{
//Instantiate Verify object
$verify = new \think\verify ();
Configure the authentication code parameter
$verify->fontsize = 14;//Verify Code font size
$verify->length = 4;//Verify code digits
$verify->imageh = 34; Verify code height
$verify->USEIMGBG = true;//Open Authenticode background
$verify->usenoise = false;//Turn off verification code interference clutter
$verify-> Entry ();
}
The code in the View verify/index.html is as follows:
2, the use of Ajax transfer parameters to achieve validation, in the controller VerifyController.class.php code is as follows:
namespace Home\controller;
Use Think\controller;
Class Verifycontroller extends Controller {public
function index () {
$this->display ();
}
Public Function Checklogin () {
$verify =new \think\verify ();
$code =$_post[' code '];//ajax verification code to get
if ($verify->check ($code)) {
$this->ajaxreturn (1);
} else{
$this->ajaxreturn (0);
}
}
Public Function Verify ()
{
//Instantiate Verify object
$verify = new \think\verify ();
Configure the authentication code parameter
$verify->fontsize = 14;//Verify Code font size
$verify->length = 4;//Verify code digits
$verify->imageh = 34; Verify code height
$verify->USEIMGBG = true;//Open Authenticode background
$verify->usenoise = false;//Turn off verification code interference clutter
$verify-> Entry ();
}
The code in the View verify/index.html is as follows:
In the 2nd method, do not forget to download jquery.min.js file download Address: http://www.jq22.com/jquery-info122
To configure the address in the configuration file common/conf/config.php:
return Array (/
* Address replacement *
/' tmpl_parse_string ' =>array (
' __js__ ' =>__root__. ') /public/js ',
),
);
The above is a small series to introduce the implementation of the Thinkphp Verification Code (form, Ajax use verification), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!