php 數(shù)學(xué)運算驗證碼實現(xiàn)代碼
更新時間:2009年10月11日 15:28:38 作者:
php 數(shù)學(xué)運算驗證碼實現(xiàn)代碼
復(fù)制代碼 代碼如下:
<?php
//-------------------------------------
// 文件說明:數(shù)學(xué)運算驗證碼
// 文件作者: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_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高精確度運算BC函數(shù)庫實例詳解
- PHP幾個數(shù)學(xué)計算的內(nèi)部函數(shù)學(xué)習(xí)整理
- PHP數(shù)學(xué)運算函數(shù)大匯總(經(jīng)典值得收藏)
- php常用數(shù)學(xué)函數(shù)匯總
- PHP使用數(shù)組實現(xiàn)矩陣數(shù)學(xué)運算的方法示例
- PHP入門教程之?dāng)?shù)學(xué)運算技巧總結(jié)
- PHP數(shù)學(xué)運算與數(shù)據(jù)處理實例分析
- 第四章 php數(shù)學(xué)運算
- PHP常見數(shù)學(xué)函數(shù)及BC高精度數(shù)學(xué)函數(shù)用法示例
相關(guān)文章
深入理解用mysql_fetch_row()以數(shù)組的形式返回查詢結(jié)果
本篇文章是對使用mysql_fetch_row()以數(shù)組的形式返回查詢結(jié)果進行了詳細的分析介紹,需要的朋友參考下2013-06-06
Can''t create/write to file ''C:\WINDOWS\TEMP\...MYSQL報錯解決方法
Can't create/write to file 'C:\WINDOWS\TEMP\...MYSQL報錯解決方法,參考下面的方法即可。2011-06-06
php cookie 作用范圍–不要在當(dāng)前頁面使用你的cookie
這兩天在調(diào)試bug的時候遇到了一個問題,就是頁面莫名其妙的會跳轉(zhuǎn)到登陸頁面2009-03-03

