Home  >  Article  >  Backend Development  >  Generate verification code in php_PHP tutorial

Generate verification code in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:07:08732browse

PHP generating verification code files is a technology that friends who learn PHP should know. This can not only improve the security of your website, but also prevent some problems such as machine registration. Below we will Let’s take a look at a simple program to generate verification codes

php verification code generation file is a technology that friends who learn PHP should know. This can not only improve the security of your website, but also You can avoid some problems such as machine registration. Let’s take a look at a simple generating verification code program


/eckNum.php
session_start();
function random(){
$srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
mt_srand();
$strs="";
for($i=0;$i<6;$i++){
$strs.=$srcstr[mt_rand(0,35)];
}
return strtoupper($strs);
}
$str=random(4); //Just use the string generated by the machine
$width = 50; //Width of verification code image
$height = 25; //Height of verification code image
@header("Content-Type:image/png");
$_SESSION["code"] = $str;
//echo $str;
$im=imagecreate($width,$height);
//Background color
$back=imagecolorallocate($im,0xFF,0xFF,0xFF);
//Blur 97xxoo point color
$pix=imagecolorallocate($im,187,230,247);
//Font color
$font=imagecolorallocate($im,41,163,238);
//Draw the blur effect point
mt_srand();
for($i=0;$i<1000;$i++)
{
imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);
}
imagestring($im, 5, 7, 5,$str, $font);
imagerectangle($im,0,0,$width-1,$height-1,$font);
imagepng($im);
imagedestroy($im);
$_SESSION["code"] = $str;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630486.htmlTechArticlePHP generation of verification code files is a technology that friends who learn PHP should know. This can not only make The security of your website has been improved, and some machine registration and other issues can also be resolved. Next...
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