Php graphic digit Verification Code

Source: Internet
Author: User

Php graphic digit Verification Code

All of the following code has been debugged by myself. Run authpage. php.

<?

/*

* Filename: authpage. php

*/

Srand (double) microtime () * 1000000 );

// Verify that the user input is consistent with the verification code

If (isset ($ _ POST ['authinput'])

{


If (strcmp ($ _ POST ['authnum'], $ _ POST ['authinput']) = 0)

Echo "Verification Successful! ";

Else

Echo "Verification Failed! ";

}

// Generate a new four-digit integer Verification Code

While ($ authnum = rand () % 10000) <1000 );

?>

<Form action = authpage. php method = post>

<Table>

Enter the verification code: <input type = text name = authinput style = "width: 80px"> <br>

<Input type = submit name = "verify" value = "submit verification code">

<Input type = hidden name = authnum value = <? Echo $ authnum;?>



</Table>

</Form>

Bytes -------------------------------------------------------------------------------------------------------------

<?
/*

* Filename: authimg. php

*/
// Generate a verification code Image
Header ("Content-type: image/PNG ");

Srand (double) microtime () * 1000000 );

$ Im = imagecreate (58,28 );

$ Black = ImageColorAllocate ($ im, 0, 0 );

$ White = ImageColorAllocate ($ im, 255,255,255 );

$ Gray = ImageColorAllocate ($ im, 200,200,200 );

Imagefill ($ im, 68, 30, $ gray );

// Print the four-digit integer verification code into the image

Imagestring ($ im, 5, 10, 8, $ HTTP_GET_VARS ['authnum'], $ white );

For ($ I = 0; $ I <50; $ I ++) // Add interference pixels

{

Imagesetpixel ($ im, rand () % 70, rand () % 30, $ gray );

}

ImagePNG ($ im );

ImageDestroy ($ im );

?>
__________________

Java-> struts
 

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.