跟着我来肢解Discuz! 解剖Discuz! 分析Discuz! 研究Discuz! 实习主刀:Cos.X

PHP验证码实用传统版

上一篇 / 下一篇  2007-06-21 10:19:57 / 个人分类:PHP

<?php

$width = "45"; // Width
$height = "20"; // Height
$bgcolor = "#ffffff"; // background color
$noise = true; // make noise
$noisenum = 100; // noise points
$border = true; // border
$bordercolor = "#000000";
$image = imageCreate($width, $height);
$back = getcolor($bgcolor);
imageFilledRectangle($image, 0, 0, $width, $height, $back);

$code = $_SESSION[authcode];
$code = 'ASDF';

$textColor = imageColorAllocate($image, rand(0,200), rand(0,200), rand(0,200));
imagestring($image, 5, 5, 2, $code, $textColor);

if ($noise == true){
    for ($i = 0; $i < $noisenum; $i++) {
        $randColor = imageColorAllocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
        imageSetPixel($image, rand(0, $width), rand(0, $height), $randColor);
    }
}

if ($border == true){
 $bordercolor = getcolor($bordercolor);
 imageRectangle($image, 0, 0, $width-1, $height-1, $bordercolor);
}

header("Content-type: image/png");
imagePng($image);

function getcolor($color)
{
    global $image;
    $r = hexdec ($color[1] . $color[2]);
    $b = hexdec ($color[3] . $color[4]);
    $g = hexdec ($color[5] . $color[6]);
    return imagecolorallocate ($image, $r, $b, $g);
}
?>


TAG: 验证码 php PHP Php

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar