12306 驗證碼 php 數學運算驗證碼實作程式碼

WBOY
發布: 2016-07-29 08:40:54
原創
1178 人瀏覽過

複製程式碼 程式碼如下:


//------------- ------------------------
// 文件說明:數學運算驗證碼
// 檔案作者:Jesse Lee
/ / 最後更新:2008-09-07
//------------------------------------ -
session_start();
$sessionvar = 'vdcode'; //Session變數名稱
$width = 150; //映像寬度
$height = 20; //圖片高度
$operator = '+-*'; //運算子
$code = array();
$code[] = mt_rand(1,9);
$code[] = $operator{mt_rand (0,2)};
$code[] = mt_rand(1,9);
$code[] = $operator{mt_rand(0,2)};
$code[] = mt_rand (1,9);
$codestr = implode('',$code);
eval("$result = ".implode('',$code).";");
$ code[] = '=';
$_SESSION[$sessionvar] = $result;
$img = ImageCreate($width,$height);
ImageColorAllocate($img, mt_rand(230,250), mt_mt_ (230,250), mt_rand(230,250));
$color = ImageColorAllocate($img, 0, 0, 0);
$offset = 0;
foreach ($code as $char) {
$offset += 20;
$txtcolor = ImageColorAllocate($img, mt_rand(0,255), mt_rand(0,150), mt_rand(0,255));
ImageChar($img, mt_rand(3,55), $3,55), $$img, mt_rand($img, mt_rand(3,55), $$img, mt_rand($img, mt_rand(3,55), $ offset, mt_rand(1,5), $char, $txtcolor);
}
for ($i=0; $i$pxcolor = ImageColorAllocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
ImageSetPixel($img, mt_rand(0,$width), mt_rand(0,$height), $pxcolor); >header('Content-type: image/png');
ImagePng($img);
?>


以上就介紹了12306 驗證碼 php 數學運算驗證碼實作程式碼,包含了12306 驗證碼方面的內容,希望對PHP教學有興趣的朋友有幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!