search
Homephp教程php手册漂亮的验证码

分享一款漂亮的验证码。
此代码来源于网络,haran只是进行了简单的改写与整合。
效果
1、漂亮的验证码
2、漂亮的验证码
3、漂亮的验证码
4、漂亮的验证码
整合步骤
一、在你的项目/Lib中建立ORG目录,将TP框架/Extend/Library/ORG/Util/Image.class.php复制到刚刚建立的目录中。
二、打开刚刚复制过来的Image.class.php,将其中的buildImageVerify方法替换为以下代码    /**<br>     +----------------------------------------------------------<br>     * 生成图像验证码<br>     +----------------------------------------------------------<br>     * @static<br>     * @access public<br>     +----------------------------------------------------------<br>     * @param string $length 位数<br>     * @param string $mode 类型<br>     * @param string $type 图像格式<br>     * @param string $width 宽度<br>     * @param string $height 高度<br>     * @param string $size 字体大小<br>     +----------------------------------------------------------<br>     * @return string<br>     +----------------------------------------------------------<br>     */<br>     static function buildImageVerify( $length=5, $mode='', $type='png', $width=300, $height=100, $size=40, $verifyName='verify') {<br> <br>         import('ORG.Util.String');<br>         $fontPath = "./Public/elephant.ttf";<br>         $randval = String::randString($length, $mode);<br>         session($verifyName, md5($randval));<br> <br>         $width = ($length * 10 + 10) > $width ? $length * 10 + 10 : $width;<br>         <br>         if ($type != 'gif' && function_exists('imagecreatetruecolor')) {<br>             $im = @imagecreatetruecolor($width, $height);<br>         } else {<br>             $im = @imagecreate($width, $height);<br>         }<br> <br>         $r = Array(225, 255, 255, 223);<br>         $g = Array(225, 236, 237, 255);<br>         $b = Array(225, 236, 166, 125);<br>         $key = mt_rand(0, 3);<br> <br>         $backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]); //背景色(随机)<br>         $borderColor = imagecolorallocate($im, 100, 100, 100); //边框色<br>         $pointColor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); //点颜色<br> <br>         imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);<br> <br>         @imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);<br>         $stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));<br>         // 干扰<br>         for ($i = 0; $i              $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));<br>             imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor);<br>         }<br>         for ($i = 0; $i              $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));<br>             imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pointColor);<br>         }<br> <br>         $x = $width/$length;<br>         for ($i = 0; $i              //imagestring($im, 5, $i * 10 + 5, mt_rand(1, 8), $randval{$i}, $stringColor);<br>             imagettftext($im, $size, rand(-30,30) ,$x*$i+5, $height/1.4, $stringColor, $fontPath,$randval{$i});<br>         }<br>         <br>         // @imagestring($im, 5, 5, 3, $randval, $stringColor);<br>         Image::output($im, $type);<br>     }三、下载elephant.ttf放置于项目目录/Public文件夹中
http://pan.baidu.com/share/link?uk=554464104&shareid=1278879446
四、建立生成验证的方法并调用<?php <br />     <br>     Class PublicAction extends Action {<br> <br>         Public function verify () {<br>             import('@.ORG.Image');<br>             Image::buildImageVerify();<br>         }<br>     }漂亮的验证码
-------------------------------------以下为懒人包-----------------------------------------------------------
将附件解压到和TP框架同级的目录中

附件 haran.rar ( 42.59 KB 下载:457 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor