圖片驗證碼有關問題

來源:互聯網
上載者: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編程~
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.