Home Backend Development PHP Tutorial php 实现验证码制造

php 实现验证码制造

Jun 13, 2016 pm 12:21 PM
100 200 image rand

php 实现验证码制作

先给看下 大致的效果

那么接下来的就直接贴代码吧

<span style="color: #000000;">php        </span><span style="color: #800080;">$image</span> = imagecreatetruecolor(100, 30); <span style="color: #008000;">//</span><span style="color: #008000;">创建画布</span>        <span style="color: #800080;">$imagecolor</span> = imagecolorallocate(<span style="color: #800080;">$image</span>, 255, 255, 255);  <span style="color: #008000;">//</span><span style="color: #008000;">背景色</span><span style="color: #000000;">        imagefill(</span><span style="color: #800080;">$image</span>, 0, 0, <span style="color: #800080;">$imagecolor</span>);  <span style="color: #008000;">//</span><span style="color: #008000;">填充背景色</span>        <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0;<span style="color: #800080;">$i</span>$i++ ){                  <span style="color: #008000;">//</span><span style="color: #008000;">循环4位数</span>                <span style="color: #800080;">$fontsize</span> = 6<span style="color: #000000;">;        </span><span style="color: #800080;">$fontcolor</span> = imagecolorallocate(<span style="color: #800080;">$image</span>, <span style="color: #008080;">rand</span>(0, 200), <span style="color: #008080;">rand</span>(0, 200), <span style="color: #008080;">rand</span>(0, 200<span style="color: #000000;">));        </span><span style="color: #800080;">$fontcontent</span> = <span style="color: #008080;">rand</span>(0, 9<span style="color: #000000;">);                </span><span style="color: #800080;">$x</span> = <span style="color: #800080;">$i</span>*100/4 + <span style="color: #008080;">rand</span>(5, 15<span style="color: #000000;">);        </span><span style="color: #800080;">$y</span> = <span style="color: #008080;">rand</span>(5, 10<span style="color: #000000;">);                imagestring(</span><span style="color: #800080;">$image</span>, <span style="color: #800080;">$fontsize</span>, <span style="color: #800080;">$x</span>, <span style="color: #800080;">$y</span>, <span style="color: #800080;">$fontcontent</span>, <span style="color: #800080;">$fontcolor</span><span style="color: #000000;">);    }                </span><span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0;<span style="color: #800080;">$i</span>$i++ ){              <span style="color: #008000;">//</span><span style="color: #008000;">循环 添加干扰点</span>                <span style="color: #800080;">$pointcolor</span> = imagecolorallocate(<span style="color: #800080;">$image</span>, <span style="color: #008080;">rand</span>(50, 200), <span style="color: #008080;">rand</span>(50, 200), <span style="color: #008080;">rand</span>(50, 200<span style="color: #000000;">));                </span><span style="color: #800080;">$x</span> = <span style="color: #008080;">rand</span>(1, 99<span style="color: #000000;">);        </span><span style="color: #800080;">$y</span> = <span style="color: #008080;">rand</span>(1, 29<span style="color: #000000;">);                imagesetpixel(</span><span style="color: #800080;">$image</span>, <span style="color: #800080;">$x</span>, <span style="color: #800080;">$y</span>, <span style="color: #800080;">$pointcolor</span><span style="color: #000000;">);    }                </span><span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0;<span style="color: #800080;">$i</span>$i++){                <span style="color: #008000;">//</span><span style="color: #008000;">循环 添加干扰线    </span>                <span style="color: #800080;">$linecolor</span> = imagecolorallocate(<span style="color: #800080;">$image</span>, <span style="color: #008080;">rand</span>(100, 250), <span style="color: #008080;">rand</span>(100, 250), <span style="color: #008080;">rand</span>(100, 250<span style="color: #000000;">));                </span><span style="color: #800080;">$x1</span> = <span style="color: #008080;">rand</span>(1, 25<span style="color: #000000;">);        </span><span style="color: #800080;">$x2</span> = <span style="color: #008080;">rand</span>(50, 75<span style="color: #000000;">);                </span><span style="color: #800080;">$y1</span> = <span style="color: #008080;">rand</span>(1, 15<span style="color: #000000;">);        </span><span style="color: #800080;">$y2</span> = <span style="color: #008080;">rand</span>(15, 25<span style="color: #000000;">);                imageline(</span><span style="color: #800080;">$image</span>, <span style="color: #800080;">$x1</span>, <span style="color: #800080;">$y1</span>, <span style="color: #800080;">$x2</span>, <span style="color: #800080;">$y2</span>, <span style="color: #800080;">$linecolor</span><span style="color: #000000;">);    }                </span><span style="color: #008080;">header</span>("content-type:image/png"<span style="color: #000000;">);        imagepng(</span><span style="color: #800080;">$image</span><span style="color: #000000;">);        imagedestroy(</span><span style="color: #800080;">$image</span><span style="color: #000000;">);</span>?>
Copy after login

 

Statement of this Website
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
How to solve 'undefined: rand.Seed' error in golang? How to solve 'undefined: rand.Seed' error in golang? Jun 25, 2023 am 08:34 AM

During the development or learning process of using Golang, we may encounter the error message of undefined:rand.Seed. This error usually occurs when you need to use a random number generator, because in Golang you need to set a random number seed before you can use the function in the rand package. This article will explain how to resolve this error. 1. Introduce the math/rand package. First, we need to introduce the math/rand package into the code. exist

How to use Bing Image Creator for free How to use Bing Image Creator for free Feb 27, 2024 am 11:04 AM

This article will introduce seven ways to get high-quality output using the free BingImageCreator. BingImageCreator (now known as ImageCreator for Microsoft Designer) is one of the great online artificial intelligence art generators. It generates highly realistic visual effects based on user prompts. The more specific, clear, and creative your prompts are, the better the results will be. BingImageCreator has made significant progress in creating high-quality images. It now uses Dall-E3 training mode, showing a higher level of detail and realism. However, its ability to consistently produce HD results depends on several factors, including fast

How to delete images from Xiaomi phones How to delete images from Xiaomi phones Mar 02, 2024 pm 05:34 PM

How to delete images on Xiaomi mobile phones? You can delete images on Xiaomi mobile phones, but most users don’t know how to delete images. Next is the tutorial on how to delete images on Xiaomi mobile phones brought by the editor. Interested users can come and join us. Let's see! How to delete images on Xiaomi mobile phone 1. First open the [Album] function in Xiaomi mobile phone; 2. Then check the unnecessary pictures and click the [Delete] button in the lower right corner; 3. Then click [Album] at the top to enter the special area , select [Recycle Bin]; 4. Then directly click [Empty Recycle Bin] as shown in the figure below; 5. Finally, directly click [Permanent Delete] to complete.

How to solve the problem of generating the same random numbers using php rand function How to solve the problem of generating the same random numbers using php rand function Mar 23, 2023 am 09:17 AM

The rand() function uses the same initial seeds on each call. The default initial seed is obtained from the operating system's time, but it only has microsecond accuracy. That is, within a very short period of time, many rand() function calls will use the same initial seed, resulting in the same random number generation. So, how to solve this problem?

Imagemagic installation Centos and Image installation tutorial Imagemagic installation Centos and Image installation tutorial Feb 12, 2024 pm 05:27 PM

LINUX is an open source operating system. Its flexibility and customizability make it the first choice of many developers and system administrators. In the LINUX system, image processing is a very important task, and Imagemagick and Image are Two very popular image processing tools, this article will introduce you to how to install Imagemagick and Image in Centos system, and provide detailed installation tutorials. Imagemagic installation Centos tutorial Imagemagick is a powerful image processing toolset, which can perform various image operations under the command line. The following are the steps to install Imagemagick on Centos system: 1

How to synchronize random number generation in Golang parallel processing? How to synchronize random number generation in Golang parallel processing? Jun 03, 2024 pm 02:53 PM

Synchronizing random number generation in Go concurrent programming: Use a mutex (sync.Mutex) to control access to the rand.Rand random number generator. Each goroutine acquires the mutex lock before generating random numbers and releases the mutex lock after generating it. This ensures that only one goroutine can access the random number generator at a time, eliminating data races.

Rare $200 coin used to knock more than $1000 off an Australian's bill Rare $200 coin used to knock more than $1000 off an Australian's bill Aug 22, 2024 pm 03:36 PM

Coins and banknotes are considered legal tender in Australia, but their worth can vary from the dollar value they are assigned if they are out of the ordinary.

Ether Whale Dumps $26M of ETH to Binance, ETH Extremely Bearish: Expert Analysis Ether Whale Dumps $26M of ETH to Binance, ETH Extremely Bearish: Expert Analysis Aug 18, 2024 am 03:15 AM

Ethereum, the world's second-biggest cryptocurrency has been consolidating in a tight range following the breaking of a bearish rising wedge price action pattern on a daily time frame.

See all articles