日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

php制作動(dòng)態(tài)隨機(jī)驗(yàn)證碼(2)_PHP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:PHP獲取一年中每個(gè)星期的開始和結(jié)束日期的方法
這篇文章主要介紹了PHP獲取一年中每個(gè)星期的開始和結(jié)束日期的方法,涉及php對(duì)日期操作的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下 本文實(shí)例講述了PHP獲取一年中每個(gè)星期的開始和結(jié)束日期的方法。分享給大家供大家參考。具體分析如下: 最近項(xiàng)目中需要做個(gè)提交周

 

代碼如下: //創(chuàng)建一張圖像
$_img = imagecreatetruecolor($_width,$_height);
//白色
$_white = imagecolorallocate($_img,255,255,255);
//填充
imagefill($_img,0,0,$_white);
if ($_flag) {
//黑色,邊框
$_black = imagecolorallocate($_img,0,0,0);
imagerectangle($_img,0,0,$_width-1,$_height-1,$_black);
}

 

4)模糊背景

 

代碼如下:
//隨機(jī)畫出6個(gè)線條
for ($i=0;$i<6;$i++) {
$_rnd_color = imagecolorallocate($_img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imageline($_img,mt_rand(0,$_width),mt_rand(0,$_height),mt_rand(0,$_width),mt_rand(0,$_height),$_rnd_color);
}
//隨機(jī)雪花
for ($i=0;$i<100;$i++) {
$_rnd_color = imagecolorallocate($_img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($_img,1,mt_rand(1,$_width),mt_rand(1,$_height),'*',$_rnd_color);
}

 

5)輸出及銷毀

 

代碼如下:
//輸出驗(yàn)證碼
for ($i=0;$i<strlen($_SESSION['code']);$i++) {
$_rnd_color = imagecolorallocate($_img,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200));
imagestring($_img,5,$i*$_width/$_rnd_code+mt_rand(1,10),mt_rand(1,$_height/2),$_SESSION['code'][$i],$_rnd_color);
}
//輸出圖像
header('Content-Type: image/png');
imagepng($_img);
//銷毀
imagedestroy($_img);

 

將其封裝在global.func.php全局函數(shù)庫中,函數(shù)名為_code(),以便調(diào)用。我們將設(shè)置$_width ,$_height ,$_rnd_code,$_flag 四個(gè)參數(shù),以增強(qiáng)函數(shù)的靈活性。

* @param int $_width 驗(yàn)證碼的長(zhǎng)度:如果要6位長(zhǎng)度推薦75+50;如果要8位,推薦75+50+50,依次類推
* @param int $_height 驗(yàn)證碼的高度
* @param int $_rnd_code 驗(yàn)證碼的位數(shù)
* @param bool $_flag 驗(yàn)證碼是否需要邊框:true有邊框, false無邊框(默認(rèn))

封裝后的代碼如下:

 

代碼如下:
<?php
/**
* [verification-code] (C)2015-2100 jingwhale.
*
* This is a freeware
* $Id: global.func.php 2015-02-05 20:53:56 jingwhale$
*/
/**
* _code()是驗(yàn)證碼函數(shù)
* @access public
* @param int $_width 驗(yàn)證碼的長(zhǎng)度:如果要6位長(zhǎng)度推薦75+50;如果要8位,推薦75+50+50,依次類推
* @param int $_height 驗(yàn)證碼的高度
* @param int $_rnd_code 驗(yàn)證碼的位數(shù)
* @param bool $_flag 驗(yàn)證碼是否需要邊框:true有邊框, false無邊框(默認(rèn))
* @return void 這個(gè)函數(shù)執(zhí)行后產(chǎn)生一個(gè)驗(yàn)證碼
*/
function _code($_width = 75,$_height = 25,$_rnd_code = 4,$_flag = false) {
//創(chuàng)建隨機(jī)碼
for ($i=0;$i<$_rnd_code;$i++) {
$_nmsg .= dechex(mt_rand(0,15));
}
//保存在session
$_SESSION['code'] = $_nmsg;
//創(chuàng)建一張圖像
$_img = imagecreatetruecolor($_width,$_height);
//白色
$_white = imagecolorallocate($_img,255,255,255);
//填充
imagefill($_img,0,0,$_white);
if ($_flag) {
//黑色,邊框
$_black = imagecolorallocate($_img,0,0,0);
imagerectangle($_img,0,0,$_width-1,$_height-1,$_black);
}
//隨即畫出6個(gè)線條
for ($i=0;$i<6;$i++) {
$_rnd_color = imagecolorallocate($_img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imageline($_img,mt_rand(0,$_width),mt_rand(0,$_height),mt_rand(0,$_width),mt_rand(0,$_height),$_rnd_color);
}
//隨即雪花
for ($i=0;$i<100;$i++) {
$_rnd_color = imagecolorallocate($_img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($_img,1,mt_rand(1,$_width),mt_rand(1,$_height),'*',$_rnd_color);
}
//輸出驗(yàn)證碼
for ($i=0;$i<strlen($_SESSION['code']);$i++) {
$_rnd_color = imagecolorallocate($_img,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200));
imagestring($_img,5,$i*$_width/$_rnd_code+mt_rand(1,10),mt_rand(1,$_height/2),$_SESSION['code'][$i],$_rnd_color);
}
//輸出圖像
header('Content-Type: image/png');
imagepng($_img);
//銷毀
imagedestroy($_img);
}
?>

 

2.創(chuàng)建驗(yàn)證機(jī)制

創(chuàng)建php驗(yàn)證頁面,通過session來檢驗(yàn)驗(yàn)證碼是否一致。

1)創(chuàng)建verification-code.php驗(yàn)證頁面

 

代碼如下:
<?php
/**
* [verification-code] (C)2015-2100 jingwhale.
*
* This is a freeware
* $Id: verification-code.php 2015-02-05 20:53:56 jingwhale$
*/
//設(shè)置字符集編碼
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>verification code</title>
<link rel="stylesheet" type="text/css" href="style/basic.css" />
</head>
<body>
<div id="testcode">
<form method="post" name="verification" action="verification-code.php?action=verification">
<dl>
<dd>驗(yàn)證碼:<input type="text" name="code" class="code" /><img src="codeimg.php" id="codeimg" /></dd>
<dd><input type="submit" class="submit" value="驗(yàn)證" /></dd>
</dl>
</form>
</div>
</body>
</html>

 

顯示如下:

php制作動(dòng)態(tài)隨機(jī)驗(yàn)證碼

2)創(chuàng)建產(chǎn)生驗(yàn)證碼圖片頁面

創(chuàng)建codeimg.php為verification-code.php html代碼里的img提供驗(yàn)證碼圖片

首先必須在codeimg.php頁面開啟session;

其次,將我們封裝好的global.func.php全局函數(shù)庫引入進(jìn)來;

最后,運(yùn)行_code();

分享:php模擬post提交數(shù)據(jù)的方法
這篇文章主要介紹了php模擬post提交數(shù)據(jù)的方法,實(shí)例分析了socket方法模擬post提交數(shù)據(jù)的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下 本文實(shí)例講述了php模擬post提交數(shù)據(jù)的方法。分享給大家供大家參考。具體如下: php模擬post提交數(shù)據(jù),用處很多,可用來網(wǎng)站的采集,

來源:模板無憂//所屬分類:PHP教程/更新時(shí)間:2015-02-13
相關(guān)PHP教程