Home > Backend Development > PHP Tutorial > 图片验证码有关问题

图片验证码有关问题

WBOY
Release: 2016-06-13 13:50:29
Original
831 people have browsed it

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

------解决方案--------------------
rand()
GD
------解决方案--------------------
session_start();

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


function my_random_password($length)
{
$result = " ";
$string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789 ";
for ($i = 0 ; $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 {
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编程~

Related labels:
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