PHP Implementation Verification Code

Source: Internet
Author: User
Tags rand

Digital Verification Code



  ?
/*
* Filename:authpage.php
*/
Session_Start ();
// Srand (Double) microtime () *1000000);
         $authnum   =   $_session [ '' Authnum '' ];
// Verify that user input is consistent with the authentication code
         if ( isset ( $_post [ '' Authinput '' ]))
{
if ( strcmp ( $_post [ '' Authinput '' ] , $_session [ '' Authnum '' ]) == 0 )
Echo   " Verify Success! " ;
Else
Echo   " validation failed! " ;
}

// to generate a new four-bit integer verification code

while (($authnum =rand ()%10000) <1000);
     ?>
< Form Action = test4 . php method = Post >
< Table >
Please enter the verification code: < input type = Text name = authinput Style = " width:80px " >< BR >
< input type = Submit Name = " Validate " value = " Submit Verification Code " >
< input type = Hidden name = Authnum Value =<?   Echo   $authnum ;  ?>>
< img SRC = authimg . PHP ? Authnum =<?   Echo   $authnum ;  ?>>
</ Table >
</ form >

authimg.php



? PHP
// Generate Captcha Picture
Header ( " Content-type:image/png " );
Srand (( Double ) Microtime () * 1000000 ); // Sow a seed that generates random numbers to facilitate the use of the following random number generation

Session_Start (); // storing random numbers in session
$_session [ '' Authnum '' ] = "" ;
$im   = Imagecreate ( the , - ); // make picture background size

$black   = Imagecolorallocate ( $im ,   0 , 0 , 0 ); // set Three Colors
$white   = Imagecolorallocate ( $im ,   255 , 255 , 255 );
$gray   = Imagecolorallocate ( $im ,   A , A , A );

Imagefill ( $im , 0 , 0 , $gray ); // using area filling method, setting (0,0)

while (( $authnum = Rand () % 100000 ) < 10000 );
// to draw a four-bit integer verification code into a picture
$_session [ '' Authnum '' ] = $authnum ;
Imagestring ( $im ,   5 ,   Ten ,   3 ,   $authnum ,   $black );
// Using Col color to draw the string s to the image represented by images of the x,y coordinates at the top left corner is 0, 0.
If font is 1,2,3,4 or 5, the built-in font is used

for ( $i = 0 ; $i < A ; $i ++ )     // adding interference pixels
{
$randcolor   = Imagecolorallocate ( $im , Rand ( 0 , 255 ) , Rand ( 0 , 255 ) , Rand ( 0 , 255 ));
Imagesetpixel ( $im ,   Rand () % -   ,   Rand () % -   ,   $randcolor );
}
Imagepng ( $im );
Imagedestroy ( $im );
?>


<

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.