Parsing the implementation code of dedeCMS verification code_PHP tutorial

WBOY
Release: 2016-07-21 15:08:11
Original
727 people have browsed it

As shown below:

Copy code The code is as follows:

$rndstring = '';
for($i=0; $i<4; $i++) $rndstring .= chr(mt_rand(65,90));
//If GD is supported, draw
if(function_exists(" imagecreate"))
{
//In some cases, Firefox may request multiple times. Refreshing the page within 5 seconds will not change the session
$ntime = time();
if(empty( $_SESSION['dd_ckstr_last']) || empty($_SESSION['dd_ckstr']) || ($ntime - $_SESSION['dd_ckstr_last'] > 5))
{
$_SESSION['dd_ckstr '] = strtolower($rndstring);
$_SESSION['dd_ckstr_last'] = $ntime;
}
$rndstring = $_SESSION['dd_ckstr'];
$rndcodelen = strlen($ rndstring);
//Create an image and set the background color
$im = imagecreate(50,20);
ImageColorAllocate($im, 255,255,255);
//Background line
$ lineColor1 = ImageColorAllocate($im,240,220,180);
$lineColor2 = ImageColorAllocate($im,250,250,170);
for($j=3;$j<=16;$j=$j+3)
{
imageline($im,2,$j,48,$j,$lineColor1);
}
for($j=2;$j<52;$j=$j+(mt_rand (3,6)))
{
imageline($im,$j,2,$j-6,18,$lineColor2);
}
//Draw a border
$ bordercolor = ImageColorAllocate($im, 0x99,0x99,0x99);
imagerectangle($im, 0, 0, 49, 19, $bordercolor);
//Output text
$fontColor = ImageColorAllocate($ im, 48,61,50);
for($i=0;$i<$rndcodelen;$i++)
{
$bc = mt_rand(0,1);
$rndstring [$i] = strtoupper($rndstring[$i]);
imagestring($im, 5, $i*10+6, mt_rand(2,4), $rndstring[$i], $fontColor);
}
header("Pragma:no-cache/r/n");
header("Cache-Control:no-cache/r/n");
header("Expires: 0/r/n");
//Output a specific type of image format, the priority is gif -> jpg ->png
if(function_exists("imagejpeg"))
{
header("content-type:image/jpeg/r/n");
imagejpeg($im);
}
else
{
header("content-type:image /png/r/n");
imagepng($im);
}
ImageDestroy($im);
exit();
}
else
{
//GD is not supported, only letters ABCD are output
$_SESSION['dd_ckstr'] = "abcd";
$_SESSION['dd_ckstr_last'] = '';
header("content- type:image/jpeg/r/n");
header("Pragma:no-cache/r/n");
header("Cache-Control:no-cache/r/n");
header("Expires:0/r/n");
$fp = fopen("data/vdcode.jpg","r");
echo fread($fp,filesize("data /vdcode.jpg"));
fclose($fp);
exit();
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327495.htmlTechArticle is as follows: Copy the code as follows: ?php $rndstring = ''; for($i=0; $i4; $i++) $rndstring .= chr(mt_rand(65,90)); //If GD is supported, drawing if(function_exists("imagecreate")...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!