Home >Backend Development >PHP Tutorial >Verification code is always wrong php verification code example code

Verification code is always wrong php verification code example code

WBOY
WBOYOriginal
2016-07-29 08:42:571121browse

If you want to use PHP's drawing function, you must first enable the function of this module. Just remove the comment in front of php_gd2.dll in php.ini.
 Start drawing below:

Copy the code The code is as follows:


  session_start();
//Generate verification code image
Header("Content-type: image/PNG");
$im = imagecreate(44,18); // Draw an image with specified width and height
$back = ImageColorAllocate($im, 245,245,245); // Define the background color
imagefill($im,0,0,$back) ; //Fill the background color into the picture just drawn
$vcodes = "";
srand((double)microtime()*1000000);
//Generate 4-digit number
for($i=0;$ i<4;$i++){
$font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // Generate random color
$authnum=rand(1,9);
$vcodes.=$authnum;
imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
}
$_SESSION['VCODE'] = $vcodes;
for($i =0;$i<100;$i++) //Add interference pixels
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); // Pixel drawing function
}
ImagePNG($im);
ImageDestroy($im);
?>


  This is basically how it is implemented , in fact, if you watermark a picture, it is nothing more than writing words into the picture. The principles are similar.
  Just use it directly
  Fill in the name of this php file and you can use it.

The above introduces the verification code is always wrong PHP verification code example code, including the content of the verification code is always wrong, I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn