天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

php5 圖片驗證碼實現(xiàn)代碼

GD庫的函數(shù)
1,imagecreatetruecolor -----創(chuàng)建一個真彩色的圖像
imagecreatetruecolor(int x_size,int y_size) //x表示寬,y表示高
2,imagecolorallocate 為一幅圖像分配顏色(調(diào)色板)
imagecolorallocate(resource image,int red,int green,int blue)//red,green,blue----三原色
3,imagestring 繪圖函數(shù)
iamgestring(resource image,font,int x,int y,內(nèi)容,顏色);
4,輸出函數(shù)
php的header是定義頭的動作,php5中支持3中類型:
1,Content-type:xxxx/yyyy
2,Location:xxxx:yyyy/zzzz
3,Status:nnn xxxxxx
xxxx/yyyy表示內(nèi)容文件的類型
如:image/gif
image/jpeg
image/png
例子:header("Content-type:image/jpeg")
GD庫中有對應(yīng)的image類型
imagejpeg(),imagegif(),imagepang()
5,imageline畫線函數(shù)
iamgeline(resource image,int x1,int y1,int x2,int y2,int color);
image ---圖片
x1 ---啟始坐標
y1
x2 ---終點坐標
y2
6,imagesetpixel畫點函數(shù)
imagesetpixel(resource image,int x,int y,int color)
7,imagettftext帶字體的寫入函數(shù)
imagettftext(resource image,float size,float angle,int x,int y,int color,string fontfile,string text)
8,php驗證碼插入中文的方法
iconv("gb2312","utf-8","字符串"); //首先要將文字轉(zhuǎn)換成utf-8格式
9,隨機函數(shù)
1,rand([int min,int max]) //rand(1,4) 生成1-4的數(shù)
2, dechex(十進制數(shù)) //轉(zhuǎn)換為十六進制
做驗證碼的步驟:
生成隨機數(shù) -- 創(chuàng)建圖片 -- 隨機數(shù)寫成圖片 --保存在session中
輸入驗證碼例子
gdchek.php
復(fù)制代碼 代碼如下:
<?php
/*
* 生成圖片驗證碼
* and open the template in the editor.
*/
session_start();
for($i=0;$i<4;$i++){
$rand.=dechex(rand(1,15)); //生成4位數(shù)包含十六進制的隨機數(shù)
}
$_SESSION[check_gd]=$rand;
$img=imagecreatetruecolor(100,30); //創(chuàng)建圖片
$bg=imagecolorallocate($img,0,0,0); //第一次生成的是背景顏色
$fc=imagecolorallocate($img,255,255,255); //生成的字體顏色
//給圖片畫線
for($i=0;$i<3;$i++){
$te=imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imageline($img,rand(0,15),0,100,30,$te);
}
//給圖片畫點
for($i=0;$i<200;$i++){
$te=imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($img,rand()%100,rand()%30,$te);
}
//首先要將文字轉(zhuǎn)換成utf-8格式
//$str=iconv("gb2312","utf-8","呵呵呵");
//加入中文的驗證
//smkai.ttf是一個字體文件,為了在別人的電腦中也能起到字體作用,把文件放到項目的根目錄,可以下載,還有本機C:/WINDOWS/Fonts中有
imagettftext($img,11,10,20,20,$fc,"simkai.ttf","你好你好");
//把字符串寫在圖片中
//imagestring($img,rand(1,6),rand(3,70),rand(3,16),$rand,$fc);
//輸出圖片
header("Content-type:image/jpeg");
imagejpeg($img);
?>

login.php
復(fù)制代碼 代碼如下:
<?php
/*
*
*
*/
session_start();
if($_POST[sub]){
//判斷驗證碼是否相同
if($_POST[gd_pic]==$_SESSION[check_gd]){
echo "驗證成功!";
}else{
echo "驗證碼錯誤";
}
}
?>
<form action="login.php" method="POST">
用戶名:<input type="text" name="user"/><br>
密碼:<input type="password" name="pwd"/><br>
驗證碼:<imput type="text" name="gd_pic"/><img src="gdchek.php"><br>
<imput type="submit" name="sub" value="submit"/>
</form>

php技術(shù)php5 圖片驗證碼實現(xiàn)代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 亚洲欧美日韩高清中文在线 | 婷婷综合久久狠狠色 | china中国gay偷拍 | 国产亚洲精品免费视频 | 中文字幕亚洲欧美日韩2019 | YY6080A旧里番在线观看 | 亚洲精品在线影院 | 动漫AV纯肉无码AV电影网 | 国产一区二区波多野结衣 | 亚洲精品第二页 | 早乙女由依在线观看 | 浪荡女天天不停挨CAO日常视 | 三叶草未满十八岁 | 蜜芽tv在线观看免费网站 | 人妻美妇疯狂迎合 | 蜜桃狠狠色伊人亚洲综合网站 | 午夜福利合集1000在线 | 伊人久久网站 | 国产 亚洲 中文字幕 久久网 | 在线中文高清资源免费观看 | 亚洲色大成网站www久久九九 | 诱咪youmiss| 国产精品视频在线自在线 | 国产99久久九九免费精品无码 | 国产精品久久久久久久久久影院 | 亚洲色噜噜狠狠网站 | 国产热久久精 | 精品国产午夜肉伦伦影院 | xx在线观看 | 牛牛精品专区在线 | 性欧美videosex18嫩 | 日本少妇无码精品12P | 久久亚洲国产精品亚洲 | 香港日本三级亚洲三级 | china18一19 第一次 | 人妻美妇疯狂迎合 | 琪琪午夜福利免费院 | 国产专区亚洲欧美另类在线 | 韩国女人高潮嗷嗷叫视频 | 伊人精品视频直播 | a级精品九九九大片免费看 A级韩国乱理伦片在线观看 |