<?php session_start(); header("Content-type:image/png"); $img_width=100; $img_height=20; srand(microtime()*100000); for($i=0;$i<4;$i++) { $new_number.=dechex(rand(0,15)); } $_SESSION[check_auth]=$new_number; $new_number=imageCreate($img_width,$img_height);//创建图象 ImageColorAllocate($new_number,255,255,255); //设置背景色为白色 for($i=0;$i<strlen($_SESSION[check_auth]);$i++) { $font=mt_rand(3,5); $x=mt_rand(1,8) + $img_width*$i/4; $y=mt_rand(1,$img_height/4); $color=imageColorAllocate($new_number,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200));//设置字符颜色 imageString($new_number,$font,$x,$y,$_SESSION[check_auth][$i],$color);//输出字符 } ImagePng($new_number); ImageDestroy($new_number); ?>
The GD library is a very powerful library for image manipulation in PHP.
First add a line of reference in php.ini: extension=php_gd2.dll
Restart apache. Make a test page var_dump(gd_info()); the output data shows that the GD library is referenced successfully.
Form auth.html
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
13 Jul 2023
Tips for generating simple graphical verification codes using PHP and GD libraries. With the development of the Internet, preventing malicious attacks and abuse has become an indispensable part of website development. CAPTCHA is a technical means widely used to verify user identity and prevent malicious robots from registering and logging in. As a popular server-side programming language, PHP, combined with the GD library, can quickly generate simple graphical verification codes. 1. Introduction to GD library The GD library is an extension library of PHP. It provides a series of functions and methods for processing images. Through the GD library,
13 Jul 2023
Detailed steps for generating verification code images using PHP and GD libraries Verification codes are a commonly used security verification mechanism that can be used to prevent malicious programs or robot automation. Automated attacks can be effectively prevented by generating a random image that requires users to enter the verification code shown in the image when logging in or registering. In this article, we will introduce in detail how to use PHP and GD library to generate verification code images. Step 1: Install and configure the GD library First, make sure your PHP environment has the GD library installed. If not installed
25 Jul 2016
Example of generating verification code by php GD library
13 Jul 2016
Two php codes that generate graphic verification codes. Verification codes are often used in PHP. Below we provide you with some PHP verification code generation classes and programs. You can just copy them and use them directly. See the code below. verify
13 Jul 2016
Summary of several methods for generating graphic verification codes in PHP. To generate a graphical verification code, you need to use the php GD library. If you do not have an account with the GD library, we need to find extension=php_gd2.dll in the php.ini file and remove the previous ";" and then restart apache or
14 Jul 2023
Tips for generating random verification code images using PHP and GD libraries. Random verification code images are a common security verification mechanism in website development. It requires users to enter the correct verification code to continue the operation. In this article, we will introduce techniques on how to generate random verification code images using PHP and the GD library. The GD library is an open source library for processing images, which provides PHP with rich image processing functions. By using the GD library, we can easily generate various verification code images. First, we need to create a PHP file named
Hot Tools
PHP dynamically randomly generates verification code class
PHP dynamically randomly generates verification code class
Simple and easy-to-use PHP verification code class
Simple and easy-to-use PHP verification code class
A PHP verification code generation code
A PHP verification code generation code