簡單的php 驗(yàn)證圖片生成函數(shù)
更新時間:2009年05月21日 02:34:22 作者:
本函數(shù)可以生成簡單的驗(yàn)證圖片,用于輸入的驗(yàn)證。
復(fù)制代碼 代碼如下:
<?php
function yzm($name,$width,$height){
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);//播下一個生成隨機(jī)數(shù)字的種子,以方便下面隨機(jī)數(shù)生成的使用
session_start();//將隨機(jī)數(shù)存入session中
$_SESSION[$name]="";
$im = imagecreate($width,$height); //制定圖片背景大小
$black = ImageColorAllocate($im, 0,0,0); //設(shè)定三種顏色
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,0,0,$gray); //采用區(qū)域填充法,設(shè)定(0,0)
while(($authnum=rand()%100000)<10000);
$_SESSION[$name]=$authnum;
imagestring($im, 5, 10, 3, $authnum, $black);
for($i=0;$i<200;$i++)//加入干擾象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
}?>
使用方法,將其建立一個php文件入yzm.php,調(diào)用<img src="aaa.php?w=100&h=20&name=aaa">
將參數(shù)調(diào)用到本函數(shù)中即可。
相關(guān)文章
驗(yàn)證坐標(biāo)在某坐標(biāo)區(qū)域內(nèi)php代碼
這篇文章主要為大家詳細(xì)介紹了驗(yàn)證坐標(biāo)在某片坐標(biāo)區(qū)域內(nèi)php代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10
當(dāng)前比較流行的兩款PHP加密、解密工具Zend Guard和iconCube介紹
這篇文章主要介紹了當(dāng)前比較流行的兩款PHP加密、解密工具Zend Guard和iconCube介紹,本文還給出了iconCube的安裝教程,需要的朋友可以參考下2014-09-09
PHP中遍歷stdclass object的實(shí)現(xiàn)代碼
從網(wǎng)上查到的方法是 用get_object_vars 把類類型轉(zhuǎn)換成數(shù)組 然后在用 foreach 遍歷即可2011-06-06
php 輸出緩沖 Output Control用法實(shí)例詳解
這篇文章主要介紹了php 輸出緩沖 Output Control用法,結(jié)合實(shí)例形式詳細(xì)分析了php 輸出緩沖 Output Control基本概念、原理、使用方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2020-03-03

