Recently, Wang Baiyuan’s blog was frequently registered by robots or maliciously attempted login. Occasionally, he received 100 rubbish registration records in one night and received 100 login error email notifications in 10 minutes, which made the very guests very silent and bored.Try to shield IP and other methods still have little effect on the situation, the very guests can not consider joining the verification code, and currently only added a verification code in the registration page, use the Limit Login Attempts plug-in control login (Chinese version of the plug-in see articles :). The following is the PHP code to generate letters, symbols, and digital captchas. It is the extreme guest who has made some modifications to the Internet code: $strpol defines which letters, symbols, and numbers to use for verification codes.
Effect demonstration:
Http://wangbaiyuan.cn/others/tools/captcha.php
Php code generates letters, symbols, digital captcha pictures
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?php Session_start(); // Generate a verification code image Header("Content-type: image/PNG"); $im = imagecreate(55,22); // Draw a 55*122 picture $back = ImageColorAllocate($im, rand(220,255),rand(220,255),rand(220,255)); // Define a random number between the background color RGB values 220-255, the background is quite bright Imagefill($im,0,0,$back); //Pick the background color into the picture just drawn $vcodes = ""; // Generate 4 digits For($i=0;$i<4;$i++){ $font = ImageColorAllocate($im, rand(50,200),rand(50,200),rand(50,200)); // Generate Random Color $strPol = "123456789ABCDEFGHIJKLMNabcdefghijklm@#&+?$";//A random string that defines what characters your CAPTCHA displays $max = strlen($strPol)-1; $authnum=$strPol[rand(0,$max)];//Choose characters randomly $vcodes.=$authnum; //The random string is drawn into the canvas with a size of 5 and the distance between the characters rand(9,12) forms a staggered and ups and downs Imagestring($im,5, 5+$i*rand(9,12),rand(1,6), $authnum, $font); } $_SESSION['captcha'] = $vcodes; For ($i = 0; $ i <100; $ i + +) / / adding interference pixels { $randcolor = ImageColorallocate($im,rand(150,200),rand(100,255),rand(0,255)); Imagesetpixel($im, rand()%70, rand()%30, $randcolor); // Draw a pixel function } ImagePNG($im); ImageDestroy($im); ?> |
This article has been printed on copyright and is protected by copyright laws. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click the "Sponsoring Author" below to call the author!
Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/php-create-letter-symbol-number-captcha-2.html
No Comment