圖片驗證碼有關問題
來源:互聯網
上載者:User
圖片驗證碼問題?
如何使用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 < $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編程~