Php jquery Verification Code

Source: Internet
Author: User
Tags image identifier

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 ();
}


?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.