搜尋
首頁後端開發php教程PHP產生帶有雪花背景的驗證碼_PHP教程
PHP產生帶有雪花背景的驗證碼_PHP教程Jul 21, 2016 pm 04:09 PM
httpphp效果原始碼產生背景驗證

效果参考(附源码)http://mail.htjs.net/yanzhengma/test.php

();?>

PHP產生帶有雪花背景的驗證碼_PHP教程



//檢驗校驗碼
if(isset(if(isset(
if(isset(
if(isset(if(isset($HTTP_POST_VARS["sub"])): if(["number"] != 
$HTTP_SESSION_VARS
[
] || empty($HTTP_POST_VARS
[
"number"
"number" "校驗碼不正確!" ; }else{     echo「驗證碼通過!"
;
}
endif;
show_source(show_source
(>
test. '
);



//以上本頁的原始碼
//以下是產生驗證碼的來源碼show_source
(
'YanZhengMa.php'

);
<font color="#000000"><font face="新宋体" color="#0000cc">); <br></font><font face="新宋体"><font color="#006600"><br></font><font color="#0000cc"></font><?php <FONT color=#006600>session_start</font><font color="#cc0000"></font>(); </font><font face="新宋体" color="#006600"><br></font>(); <font face="新宋体"><font color="#ff9900"><br><br>(); </font><font color="#0000cc"></font> <font color="#006600"></font>"login_check_number"<font color="#0000cc"></font><font color="#006600">); </font></font><font face="新宋体"><font color="#ff9900">//昨晚看到了chianren上的驗證碼效果,就考慮了一下,用PHP的GD庫完成了類似功能<br>//先成生背景,再把產生的驗證碼放上去</font><font color="#0000cc"></font>$img_height<font color="#006600"></font>=<font color="#0000cc"></font> 120</font><font face="新宋体">;    <font color="#006600"><br></font><font color="#0000cc">//先定義圖片的長、寬</font><font color="#006600"></font>$img_width<font color="#cc0000"></font><font color="#006600">$img_width</font><font color="#cc0000"></font>$img_width40<font face="新宋体" color="#006600"><br></font><font face="新宋体">; <font color="#ff9900">if(<br></font>$HTTP_GET_VARS<font color="#006600"></font>[<font color="#0000cc"></font><font color="#006600"></font>[<font color="#0000cc"></font> 🎜>]== <font color="#006600"></font>"init"<font color="#0000cc"></font><font color="#006600">){ </font>    <font color="#0000cc"></font><font color="#006600">//srand(microtime(microtime PHP420後,srand不是必須的</font>    <font color="#0000cc"></font>for(</font><font face="新宋体">$Tmpa<font color="#006600"><br>=</font><font color="#0000cc">0</font><font color="#006600">=</font><font color="#0000cc">0</font><font color="#006600">; </font>$Tmpa<font color="#0000cc"></font></font>4<font color="#0000cc"></font>;<font color="#006600"></font>$Tmpa<font color="#0000cc"></font>        </font><font face="新宋体" color="#006600">$nmsg<br></font>.=<font face="新宋体"><font color="#ff9900">dechex<br><br>(<br></font>rand<font color="#0000cc"></font>(<font color="#006600"></font>0<font color="#0000cc"></font>,<font color="#006600"></font>15<font color="#0000cc"></font></font>)); <font face="新宋体" color="#006600">    }<br><br></font>    }<font face="新宋体"><font color="#ff9900"><br>//by sports98 >    $HTTP_SESSION_VARS[login_check_number<sg>;     //$HTTP_SESSION_VARS[login_check_number] = strval /"1111","9999")); session中    //誰能下補充,可以同時產生字母和數字啊? ?----由sports98完成了<br><br>    </sg></font><font color="#0000cc">$aimg </font><font color="#006600">= </font><font color="#0000cc">imageCreate</font>= <font color="#006600"></font>imageCreate<font color="#0000cc">= </font><font color="#006600"> img_height</font><font color="#0000cc">,</font><font color="#006600">$img_width</font></font>);    <font face="新宋体"><font color="#ff9900"><br><afate> </afate></font><font color="#0000cc">(</font><font color="#006600">$aimg</font><font color="#0000cc">, </font><font color="#006600">255</font><font color="#0000cc">,</font>255<font color="#006600"></font>,<font color="#0000cc"><font color="#006600">255</font><font color="#0000cc">);            </font><font color="#006600"></font>//圖片底色,Image<orocate></orocate></font>$black <font face="新宋体"><font color="#ff9900">= <br></font>ImageColorAllocate<font color="#0000cc"></font>(<font color="#006600"><font color="#0000cc">,</font><font color="#006600">0</font><font color="#0000cc">,</font><font color="#006600">0</font><font color="#0000cc">);      定義所需的黑色</font>    <font color="#006600"></font>ImageRectangle<font color="#0000cc"></font>(<font color="#006600"></font>$aimg<font color="#0000cc"></font>,<font color="#006600"></font>$aimg</font><font face="新宋体">,<font color="#ff9900"><br>$aimg</font><font color="#0000cc">,</font><font color="#006600">$aimg</font><font color="#0000cc">,</font><font color="#006600">$aimg</font><font color="#0000cc"> </font><font color="#006600">0</font><font color="#0000cc">,</font><font color="#006600">$img_height</font><font color="#0000cc">-</font><font color="#006600">1</font><font color="#0000cc">-</font><font color="#006600">1</font><font color="#0000cc">,</font><font color="#006600"> img_width</font><font color="#0000cc">-</font><font color="#006600">1</font><font color="#0000cc">,</font><font color="#006600">$black</font></font>);<font face="新宋体"><font color="#ff9900">$black<br><br>);<br></font><font color="#006600"> //先成一黑色的長方形把圖片包圍</font><font color="#0000cc">    //下面該產生雪花背景了,其實就是在圖片上產生一些符號</font>    <font color="#006600"></font> (<font color="#0000cc"></font><font color="#006600"> $i</font><font color="#0000cc">=</font><font color="#006600">1</font><font color="#0000cc">; </font><font color="#006600">$i</font><font color="#0000cc">10<font color="#006600">; </font></font>$i<font face="新宋体"><font color="#ff9900"> ) {    <br></font><font color="#0000cc"></font>//先用100個測試<font color="#006600"></font><font color="#0000cc">//先用100個測試</font><font color="#006600"></font>//先用100個測試<font color="#0000cc"></font><font color="#006600"> 🎜></font>(<font color="#0000cc"></font>$aimg<font color="#006600"></font>,<font color="#0000cc"></font>1<font color="#006600"></font>,<font color="#0000cc"></font>mt_rand<font color="#006600"></font>(<font color="#0000cc"></font>1<font color="#006600"></font>,<font color="#0000cc"></font>$img_height<font color="#006600"></font>),<font color="#0000cc"></font>mt_rand<font color="#006600"></font><font color="#cc0000"></font>mt_rand<font color="#006600"></font><font color="#0000cc"> </font><font color="#006600">,</font><font color="#0000cc">$img_width</font><font color="#006600">),</font><font color="#0000cc">"*"</font><font color="#006600">,</font><font color="#0000cc">"*"</font><font color="#006600">,</font><font color="#0000cc">"*"</font><font color="#006600">,</font><font color="#0000cc"> 🎜>(</font><font color="#006600">$aimg</font><font color="#0000cc">,</font><font color="#006600">mt_rand</font><font color="#0000cc">(</font><font color="#006600">200</font><font color="#0000cc">(</font><font color="#006600">200</font><font color="#0000cc"></font><font color="#006600">255</font><font color="#0000cc">),</font></font>mt_rand<font face="新宋体" color="#006600"><br>(</font><font face="新宋体" color="#ff9900">200<br></font>,<font face="新宋体" color="#006600"><br>200<br></font>,<font face="新宋体"><font color="#ff9900">200,200,200,200,200,200、 🎜>),mt_rand(200,255,255 );         //哈,看到了吧,其實也不是雪花,就是產生*號而已。為了使它們看起來"雜亂無章、5顏6色",就得在1個1個生成它們的時候,讓它們的位置、顏色,甚至大小都用隨機數,rand()或mt_rand都可以完成。     }     //上方產生了背景,現在就該把已經產生的隨機數放上來了。道理跟上面差不多,隨機數1個1個地放,同時讓他們的位置、大小、顏色都用成隨機數~~ <br>    //為了區別於背景,這裡的顏色不超過200,上面的不小於200 <br>    </font><font color="#006600">for (</font><font color="#0000cc">$i</font><font color="#006600">=</font><font color="#0000cc">0</font><font color="#006600">=</font><font color="#0000cc">0</font><font color="#006600"></font><font color="#0000cc">0</font><font color="#006600"></font></font></font>strlen<font color="#0000cc"></font>(<font color="#006600"></font>$HTTP_SESSION_VARS<font color="#0000cc"></font>[</font><font face="新宋体"><br>$i</font><font color="#0000cc"></font><font color="#006600"> ){ </font>        <font color="#0000cc"></font>imageString<font color="#006600"> 🎜></font>, <font color="#0000cc"></font>mt_rand<font color="#006600"></font>(<font color="#0000cc"></font>3<font color="#006600"></font>,<font color="#0000cc"></font>5<font color="#006600"></font>,<font color="#0000cc"></font>5<font color="#006600">5</font> 🎜><font color="#0000cc">$i</font><font color="#006600">*</font><font color="#0000cc">$img_height</font><font color="#006600">/</font><font color="#0000cc">4</font><font color="#006600">/</font><font color="#0000cc">4</font><font color="#006600">/</font><font color="#0000cc">4</font><font color="#006600">(</font><font color="#0000cc">1</font><font color="#006600">,</font><font color="#0000cc">10</font><font color="#006600">),</font><font color="#0000cc">mt_y</font><font color="#006600">),</font><font color="#0000cc">mt_rand</font><font color="#006600">1</font><font color="#0000cc">,</font><font color="#006600">$img_width</font><font color="#0000cc">/</font><font color="#006600">2</font><font color="#0000cc">/</font><font color="#006600">2</font><font color="#0000cc">/</font><font color="#006600">2</font><font color="#0000cc">/</font><font color="#006600">2</font></font>[<font color="#006600"></font>login_check_number<font color="#0000cc"></font>][<font color="#006600"></font>$i<font color="#0000cc"></font>,<font color="#006600"></font>$i<font color="#0000cc"></font>,<font color="#006600">,</font>(<font color="#0000cc"></font>$aimg<font color="#006600"></font>,<font color="#0000cc"></font>mt_rand<font color="#006600"></font>(<font color="#0000cc"></font>0<font color="#006600"></font><font color="#0000cc"></font>0<font color="#006600"></font><font color="#0000cc"></font>100
),
mt_rand
(0,0,
1
,
15 🎜>),mt_rand(0
,
200));
    }     Header(
 🎜>
//告訴瀏覽器,下面的資料是圖片,而不要按文字顯示
    
ImagePng
>$aimg

);                     在中    

ImageDestroy($aimg$aimg$aimg
$aimg
$aimg$aimg> 🎜>?> http://www.bkjia.com/PHPjc/314647.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314647.htmlTechArticle效果參考(附源碼)http://mail.htjs.net/yanzhengma/test.php ?session_start ( ); ? FORM METHOD=POST ACTION="" input type=text name=number maxlength=4img src="YanZhengMa.php?act=i...
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace("&nbsp;","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么查找字符串是第几位php怎么查找字符串是第几位Apr 22, 2022 pm 06:48 PM

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。