Heim Backend-Entwicklung PHP-Tutorial PHP生成带有雪花背景的验证码_PHP教程

PHP生成带有雪花背景的验证码_PHP教程

Jul 21, 2016 pm 04:09 PM
http php 效果 源码 生成 von Code 背景 验证

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

();?>


PHP生成带有雪花背景的验证码_PHP教程



//检验校验码
if(isset($HTTP_POST_VARS["sub"
])):
if(
$HTTP_POST_VARS["number"] != $HTTP_SESSION_VARS[login_check_number] || empty($HTTP_POST_VARS["number"
])){
    echo 
"校验码不正确!" 
;
}else{
    echo
"验证码通过!"
;
}
endif;
show_source('test.php'
);
//以上本页的源码


//以下是生成验证码的源码
show_source('YanZhengMa.php'
);
?>
<font color="#000000"><font face="新宋体" color="#0000cc"><?php <BR>session_start</font><font face="新宋体"><font color="#006600">(); <br></font><font color="#0000cc">session_register</font><font color="#006600">(</font><font color="#cc0000">"login_check_number"</font></font><font face="新宋体" color="#006600">); <br></font><font face="新宋体"><font color="#ff9900">//昨晚看到了chianren上的验证码效果,就考虑了一下,用PHP的GD库完成了类似功能 <br>//先成生背景,再把生成的验证码放上去 <br></font><font color="#0000cc">$img_height</font><font color="#006600">=</font><font color="#0000cc">120</font><font color="#006600">;    </font></font><font face="新宋体"><font color="#ff9900">//先定义图片的长、宽 <br></font><font color="#0000cc">$img_width</font><font color="#006600">=</font><font color="#0000cc">40</font></font><font face="新宋体"><font color="#006600">; <br>if(</font><font color="#0000cc">$HTTP_GET_VARS</font><font color="#006600">[</font><font color="#cc0000">"act"</font><font color="#006600">]== </font><font color="#cc0000">"init"</font></font><font face="新宋体" color="#006600">){ <br>    </font><font face="新宋体"><font color="#ff9900">//srand(microtime() * 100000);//PHP420后,srand不是必须的 <br>    </font><font color="#006600">for(</font><font color="#0000cc">$Tmpa</font><font color="#006600">=</font><font color="#0000cc">0</font><font color="#006600">;</font><font color="#0000cc">$Tmpa</font><font color="#006600"><font color="#0000cc">4</font><font color="#006600">;</font><font color="#0000cc">$Tmpa</font></font><font face="新宋体"><font color="#006600">++){ <br>        </font><font color="#0000cc">$nmsg</font><font color="#006600">.=</font><font color="#0000cc">dechex</font><font color="#006600">(</font><font color="#0000cc">rand</font><font color="#006600">(</font><font color="#0000cc">0</font><font color="#006600">,</font><font color="#0000cc">15</font></font><font face="新宋体" color="#006600">)); <br>    }</font><font face="新宋体"><font color="#ff9900">//by sports98 <br><br><br>    </font><font color="#0000cc">$HTTP_SESSION_VARS</font><font color="#006600">[</font><font color="#0000cc">login_check_number</font><font color="#006600">] = </font><font color="#0000cc">$nmsg</font></font><font face="新宋体" color="#006600">; <br><br>    </font><font face="新宋体"><font color="#ff9900">//$HTTP_SESSION_VARS[login_check_number] = strval(mt_rand("1111","9999"));    //生成4位的随机数,放入session中 <br>    //谁能做下补充,可以同时生成字母和数字啊??----由sports98完成了 <br><br>    </font><font color="#0000cc">$aimg </font><font color="#006600">= </font><font color="#0000cc">imageCreate</font><font color="#006600">(</font><font color="#0000cc">$img_height</font><font color="#006600">,</font><font color="#0000cc">$img_width</font><font color="#006600">);    </font></font><font face="新宋体"><font color="#ff9900">//生成图片 <br>    </font><font color="#0000cc">ImageColorAllocate</font><font color="#006600">(</font><font color="#0000cc">$aimg</font><font color="#006600">, </font><font color="#0000cc">255</font><font color="#006600">,</font><font color="#0000cc">255</font><font color="#006600">,</font><font color="#0000cc">255</font><font color="#006600">);            </font></font><font face="新宋体"><font color="#ff9900">//图片底色,ImageColorAllocate第1次定义颜色PHP就认为是底色了 <br>    </font><font color="#0000cc">$black </font><font color="#006600">= </font><font color="#0000cc">ImageColorAllocate</font><font color="#006600">(</font><font color="#0000cc">$aimg</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 face="新宋体"><font color="#ff9900">//定义需要的黑色 <br>    </font><font color="#0000cc">ImageRectangle</font><font color="#006600">(</font><font color="#0000cc">$aimg</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">$img_height</font><font color="#006600">-</font><font color="#0000cc">1</font><font color="#006600">,</font><font color="#0000cc">$img_width</font><font color="#006600">-</font><font color="#0000cc">1</font><font color="#006600">,</font><font color="#0000cc">$black</font><font color="#006600">);</font></font><font face="新宋体"><font color="#ff9900">//先成一黑色的矩形把图片包围 <br><br>    //下面该生成雪花背景了,其实就是在图片上生成一些符号 <br>    </font><font color="#006600">for (</font><font color="#0000cc">$i</font><font color="#006600">=</font><font color="#0000cc">1</font><font color="#006600">; </font><font color="#0000cc">$i</font><font color="#006600"><font color="#0000cc">100</font><font color="#006600">; </font><font color="#0000cc">$i</font><font color="#006600">++) {    </font></font><font face="新宋体"><font color="#ff9900">//先用100个做测试 <br>        </font><font color="#0000cc">imageString</font><font color="#006600">(</font><font color="#0000cc">$aimg</font><font color="#006600">,</font><font color="#0000cc">1</font><font color="#006600">,</font><font color="#0000cc">mt_rand</font><font color="#006600">(</font><font color="#0000cc">1</font><font color="#006600">,</font><font color="#0000cc">$img_height</font><font color="#006600">),</font><font color="#0000cc">mt_rand</font><font color="#006600">(</font><font color="#0000cc">1</font><font color="#006600">,</font><font color="#0000cc">$img_width</font><font color="#006600">),</font><font color="#cc0000">"*"</font><font color="#006600">,</font><font color="#0000cc">imageColorAllocate</font><font color="#006600">(</font><font color="#0000cc">$aimg</font><font color="#006600">,</font><font color="#0000cc">mt_rand</font><font color="#006600">(</font><font color="#0000cc">200</font><font color="#006600">,</font><font color="#0000cc">255</font><font color="#006600">),</font><font color="#0000cc">mt_rand</font><font color="#006600">(</font><font color="#0000cc">200</font><font color="#006600">,</font><font color="#0000cc">255</font><font color="#006600">),</font><font color="#0000cc">mt_rand</font><font color="#006600">(</font><font color="#0000cc">200</font><font color="#006600">,</font><font color="#0000cc">255</font></font><font face="新宋体" color="#006600">))); <br>        </font><font face="新宋体" color="#ff9900">//哈,看到了吧,其实也不是雪花,就是生成*号而已。为了使它们看起来"杂乱无章、5颜6色",就得在1个1个生成它们的时候,让它们的位置、颜色,甚至大小都用随机数,rand()或mt_rand都可以完成。 <br>    </font><font face="新宋体" color="#006600">} <br><br>    </font><font face="新宋体"><font color="#ff9900">//上面生成了背景,现在就该把已经生成的随机数放上来了。道理和上面差不多,随机数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">$i</font><font color="#006600"><font color="#0000cc">strlen</font><font color="#006600">(</font><font color="#0000cc">$HTTP_SESSION_VARS</font><font color="#006600">[</font><font color="#0000cc">login_check_number</font><font color="#006600">]);</font><font color="#0000cc">$i</font></font><font face="新宋体"><font color="#006600">++){ <br>        </font><font color="#0000cc">imageString</font><font color="#006600">(</font><font color="#0000cc">$aimg</font><font color="#006600">, </font><font color="#0000cc">mt_rand</font><font color="#006600">(</font><font color="#0000cc">3</font><font color="#006600">,</font><font color="#0000cc">5</font><font color="#006600">),</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">mt_rand</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_rand</font><font color="#006600">(</font><font color="#0000cc">1</font><font color="#006600">,</font><font color="#0000cc">$img_width</font><font color="#006600">/</font><font color="#0000cc">2</font><font color="#006600">), </font><font color="#0000cc">$HTTP_SESSION_VARS</font><font color="#006600">[</font><font color="#0000cc">login_check_number</font><font color="#006600">][</font><font color="#0000cc">$i</font><font color="#006600">],</font><font color="#0000cc">imageColorAllocate</font><font color="#006600">(</font><font color="#0000cc">$aimg</font><font color="#006600">,</font><font color="#0000cc">mt_rand</font><font color="#006600">(</font><font color="#0000cc">0</font><font color="#006600">,</font><font color="#0000cc">100</font><font color="#006600">),</font><font color="#0000cc">mt_rand</font><font color="#006600">(</font><font color="#0000cc">0</font><font color="#006600">,</font><font color="#0000cc">150</font><font color="#006600">),</font><font color="#0000cc">mt_rand</font><font color="#006600">(</font><font color="#0000cc">0</font><font color="#006600">,</font><font color="#0000cc">200</font></font><font face="新宋体"><font color="#006600">))); <br>    } <br>    </font><font color="#0000cc">Header</font><font color="#006600">(</font><font color="#cc0000">"Content-type: image/png"</font><font color="#006600">);    </font></font><font face="新宋体"><font color="#ff9900">//告诉浏览器,下面的数据是图片,而不要按文字显示 <br>    </font><font color="#0000cc">ImagePng</font><font color="#006600">(</font><font color="#0000cc">$aimg</font><font color="#006600">);                    </font></font><font face="新宋体"><font color="#ff9900">//生成png格式。。。嘿嘿效果蛮像回事的嘛。。。 <br>    </font><font color="#0000cc">ImageDestroy</font><font color="#006600">(</font><font color="#0000cc">$aimg</font></font><font face="新宋体"><font color="#006600">); <br>} <br><br></font><font color="#0000cc">?></font> </font></font></font></font></font>

www.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...
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
2 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Repo: Wie man Teamkollegen wiederbelebt
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Abenteuer: Wie man riesige Samen bekommt
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

CakePHP-Projektkonfiguration CakePHP-Projektkonfiguration Sep 10, 2024 pm 05:25 PM

In diesem Kapitel werden wir die Umgebungsvariablen, die allgemeine Konfiguration, die Datenbankkonfiguration und die E-Mail-Konfiguration in CakePHP verstehen.

PHP 8.4 Installations- und Upgrade-Anleitung für Ubuntu und Debian PHP 8.4 Installations- und Upgrade-Anleitung für Ubuntu und Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 bringt mehrere neue Funktionen, Sicherheitsverbesserungen und Leistungsverbesserungen mit einer beträchtlichen Menge an veralteten und entfernten Funktionen. In dieser Anleitung wird erklärt, wie Sie PHP 8.4 installieren oder auf PHP 8.4 auf Ubuntu, Debian oder deren Derivaten aktualisieren. Obwohl es möglich ist, PHP aus dem Quellcode zu kompilieren, ist die Installation aus einem APT-Repository wie unten erläutert oft schneller und sicherer, da diese Repositorys in Zukunft die neuesten Fehlerbehebungen und Sicherheitsupdates bereitstellen.

CakePHP Datum und Uhrzeit CakePHP Datum und Uhrzeit Sep 10, 2024 pm 05:27 PM

Um in cakephp4 mit Datum und Uhrzeit zu arbeiten, verwenden wir die verfügbare FrozenTime-Klasse.

CakePHP-Datei hochladen CakePHP-Datei hochladen Sep 10, 2024 pm 05:27 PM

Um am Datei-Upload zu arbeiten, verwenden wir den Formular-Helfer. Hier ist ein Beispiel für den Datei-Upload.

CakePHP-Routing CakePHP-Routing Sep 10, 2024 pm 05:25 PM

In diesem Kapitel lernen wir die folgenden Themen im Zusammenhang mit dem Routing kennen.

Besprechen Sie CakePHP Besprechen Sie CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP ist ein Open-Source-Framework für PHP. Es soll die Entwicklung, Bereitstellung und Wartung von Anwendungen erheblich vereinfachen. CakePHP basiert auf einer MVC-ähnlichen Architektur, die sowohl leistungsstark als auch leicht zu verstehen ist. Modelle, Ansichten und Controller gu

So richten Sie Visual Studio-Code (VS-Code) für die PHP-Entwicklung ein So richten Sie Visual Studio-Code (VS-Code) für die PHP-Entwicklung ein Dec 20, 2024 am 11:31 AM

Visual Studio Code, auch bekannt als VS Code, ist ein kostenloser Quellcode-Editor – oder eine integrierte Entwicklungsumgebung (IDE) –, die für alle gängigen Betriebssysteme verfügbar ist. Mit einer großen Sammlung von Erweiterungen für viele Programmiersprachen kann VS Code c

CakePHP erstellt Validatoren CakePHP erstellt Validatoren Sep 10, 2024 pm 05:26 PM

Der Validator kann durch Hinzufügen der folgenden zwei Zeilen im Controller erstellt werden.

See all articles