This tutorial mainly uses jquery ajax to implement advance verification of the jquery php verification code without refreshing it.
This tutorial mainly uses jquery ajax to implement the advance verification of the verification code in the jquery php tutorial without refreshing.
// Call this page. If the following formula is set up, a verification code image is generated.
If ($ _ get ['action'] = 'verifycode '){
Rand_create ();
}
// Verification Code Image Generation
Function rand_create (){
// Notify the browser that a png image will be output
Header ('content-type: image/png ');
// Prepare the random number generator Seeds
Srand (double) microtime () * 1000000 );
// Prepare Image Parameters
$ Im = imagecreate (62,20 );
$ Black = imagecolorallocate ($ im, 0); // rgb black identifier
$ White = imagecolorallocate ($ im, 255,255,255); // rgb white identifier
$ Gray = imagecolorallocate ($ im, 200,200,200); // rgb gray identifier
// Start plotting
Imagefill ($ im, 0, 0, $ gray );
While ($ randval = rand () % 100000) <10000 );{
// Print the four-digit integer verification code into the image
Session_start ();
$ _ Session ['login _ check_num '] = $ randval;
Imagestring ($ im, 5, 10, 3, $ randval, $ black );
}
// Add interference pixels
For ($ I = 0; I I <200; $ I ++ ){
$ Randcolor = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
Imagesetpixel ($ im, rand () % 70, rand () % 30, $ randcolor );
}
// Output verification Image
Imagepng ($ im );
// Destroy the image identifier
Imagedestroy ($ im );
}
?>
The verification code displayed on the Static Page is:
Verification Code:
The ajax Verification Code of jquery is as follows:
$. Post ("session. php ",
{Reg_code: $ ("# reg_code"). val ()},
Function (data ){
If (data = "1 "){
// Do...
} Else {
Do ...}
}
);
The php page for ajax verification is called session. php and its code is:
Session_start ();
// Verify the verification code
If ($ _ post ['reg _ Code'] = $ _ session ['login _ check_num ']) {
Echo 1;
} Else {
Echo 0;
Exit ();
}
?>