php 數(shù)學(xué)運(yùn)算驗(yàn)證碼實(shí)現(xiàn)代碼
更新時(shí)間:2009年10月11日 15:28:38 作者:
php 數(shù)學(xué)運(yùn)算驗(yàn)證碼實(shí)現(xiàn)代碼
復(fù)制代碼 代碼如下:
<?php
//-------------------------------------
// 文件說(shuō)明:數(shù)學(xué)運(yùn)算驗(yàn)證碼
// 文件作者:Jesse Lee
// 最后更新:2008-09-07
//-------------------------------------
session_start();
$sessionvar = 'vdcode'; //Session變量名稱
$width = 150; //圖像寬度
$height = 20; //圖像高度
$operator = '+-*'; //運(yùn)算符
$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_rand(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,5), $offset, mt_rand(1,5), $char, $txtcolor);
}
for ($i=0; $i<100; $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);
?>
您可能感興趣的文章:
- PHP高精確度運(yùn)算BC函數(shù)庫(kù)實(shí)例詳解
- PHP幾個(gè)數(shù)學(xué)計(jì)算的內(nèi)部函數(shù)學(xué)習(xí)整理
- PHP數(shù)學(xué)運(yùn)算函數(shù)大匯總(經(jīng)典值得收藏)
- php常用數(shù)學(xué)函數(shù)匯總
- PHP使用數(shù)組實(shí)現(xiàn)矩陣數(shù)學(xué)運(yùn)算的方法示例
- PHP入門教程之?dāng)?shù)學(xué)運(yùn)算技巧總結(jié)
- PHP數(shù)學(xué)運(yùn)算與數(shù)據(jù)處理實(shí)例分析
- 第四章 php數(shù)學(xué)運(yùn)算
- PHP常見數(shù)學(xué)函數(shù)及BC高精度數(shù)學(xué)函數(shù)用法示例
相關(guān)文章
phplock(php進(jìn)程鎖) v1.0 beta1
PHP在多進(jìn)程模式下(并發(fā)的web訪問(wèn))由于沒(méi)有內(nèi)置的鎖支持,在處理一些資源的之后,很容易出現(xiàn)并發(fā)性問(wèn)題。2009-11-11
PHP的簡(jiǎn)單跳轉(zhuǎn)提示的實(shí)現(xiàn)詳解
這篇文章主要介紹了PHP的簡(jiǎn)單跳轉(zhuǎn)提示的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03
深入理解用mysql_fetch_row()以數(shù)組的形式返回查詢結(jié)果
本篇文章是對(duì)使用mysql_fetch_row()以數(shù)組的形式返回查詢結(jié)果進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
Can''t create/write to file ''C:\WINDOWS\TEMP\...MYSQL報(bào)錯(cuò)解決方法
Can't create/write to file 'C:\WINDOWS\TEMP\...MYSQL報(bào)錯(cuò)解決方法,參考下面的方法即可。2011-06-06
php cookie 作用范圍–不要在當(dāng)前頁(yè)面使用你的cookie
這兩天在調(diào)試bug的時(shí)候遇到了一個(gè)問(wèn)題,就是頁(yè)面莫名其妙的會(huì)跳轉(zhuǎn)到登陸頁(yè)面2009-03-03

