日期:2014-05-17  浏览次数:20575 次

图片验证码问题?
如何使用php代码生成随机的图片验证码呀?请发出代码,谢谢大家了!!

------解决方案--------------------
rand()
GD
------解决方案--------------------
<?php
session_start();

$password = my_random_password(5);
$_SESSION[ "CheckCode "] = $password;


function my_random_password($length)
{
$result = " ";
$string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789 ";
for ($i = 0 ; $i < $length ; $i++)
{
$result .= $string[mt_rand(0 , strlen($string) - 1)];
}
return $result;
}

header ( "content-type: image/gif ");
//图像长宽初始化
$image_x = $_GET[ 'width '];
$image_y = $_GET[ 'height '];
//创建图片
$image = imagecreate($image_x , $image_y);
//定义背景色
$background_color = imagecolorallocate($image , 0xFF , 0xFF , 0xFF);
//定义所需要的颜色
$black_color = imagecolorallocate($image, 100, 50, 255);
$gray_color = imagecolorallocate($image , 0xdd , 0xdd , 0xdd);
//循环生成雪花点
for ($i = 0 ; $i < 1000 ; $i++)
{
imagesetpixel($image , mt_rand(0 , $image_x) , mt_rand(0 , $image_y) , $gray_color);
}
//把随机字符串输入图片
//imagestring($image, 8, 10, 3, $password, $black_color);
imagettftext($image, 12, 0, 5, 17, $black_color, './ariblk.ttf ', $password);
//生成矩形边框
imagerectangle($image , 0 , 0 , $image_x - 1 , $image_y - 1 , $black_color);
//生成图片
imagegif($image);
//释放与$image关联的内存
imagedestroy($image);
?>
------解决方案--------------------
效果请看 http://www.iebsoft.com/imall/system/login.php
------解决方案--------------------
rand()
GD编程~