


What should I do if the php verification code remains unchanged?
Solutions to keep the PHP verification code unchanged: 1. Use the "javascript:ckimg();" method to change a verification code; 2. Use "οnclick="this.src='..." The method is to click to change the picture.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
What should I do if the php verification code remains unchanged?
php verification code changes without refreshing (replacement)
test.php
<html> <head> <script> function ckimg(){ document.getElementById('img').src="validateCode2.php?"+new Date().getTime(); } </script> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <!--第一种方法--> <a href="javascript:ckimg();" title="更换一张验证码图片"><img src="validateCode2.php" id="img" alt="看不清,请换一张" /></a> <a href="javascript:ckimg();" title="更换一张验证码图片">看不清,请换一张</a> <!--第二种方法--> <img src="validateCode2.php" alt="看不清,点击换图片" id="img" οnclick="this.src='validateCode2.php?'+new Date().getTime();" style='cursor:pointer;'> </body> </html>
Production verification The code class contains some parameters for verification code generation, such as: size, color, symbol type for displaying verification code
validateCode2.php
<?php session_start(); class Authnum { //图片对象、宽度、高度、验证码长度 private $im; private $im_width; private $im_height; private $len; //随机字符串、y轴坐标值、随机颜色 private $randnum; private $y; private $randcolor; //背景色的红绿蓝,默认是浅灰色 public $red=238; public $green=238; public $blue=238; /** * 可选设置:验证码类型、干扰点、干扰线、Y轴随机 * 设为 false 表示不启用 **/ //默认是大小写数字混合型,1 2 3 分别表示 小写、大写、数字型 public $ext_num_type=''; public $ext_pixel = false; //干扰点 public $ext_line = false; //干扰线 public $ext_rand_y= true; //Y轴随机 function __construct ($len=4,$im_width='',$im_height=25) { // 验证码长度、图片宽度、高度是实例化类时必需的数据 $this->len = $len; $im_width = $len * 15; $this->im_width = $im_width; $this->im_height= $im_height; $this->im = imagecreate($im_width,$im_height); } // 设置图片背景颜色,默认是浅灰色背景 function set_bgcolor () { imagecolorallocate($this->im,$this->red,$this->green,$this->blue); } // 获得任意位数的随机码 function get_randnum () { $an1 = 'abcdefghijklmnopqrstuvwxyz'; $an2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $an3 = '0123456789'; if ($this->ext_num_type == '') $str = $an1.$an2.$an3; if ($this->ext_num_type == 1) $str = $an1; if ($this->ext_num_type == 2) $str = $an2; if ($this->ext_num_type == 3) $str = $an3; for ($i = 0; $i < $this->len; $i++) { $start = rand(1,strlen($str) - 1); $randnum .= substr($str,$start,1); } $this->randnum = $randnum; $_SESSION[an] = $this->randnum; } // 获得验证码图片Y轴 function get_y () { if ($this->ext_rand_y) $this->y = rand(5, $this->im_height/5); else $this->y = $this->im_height / 4 ; } // 获得随机色 function get_randcolor () { $this->randcolor = imagecolorallocate($this->im,rand(0,100),rand(0,150),rand(0,200)); } // 添加干扰点 function set_ext_pixel () { if ($this->ext_pixel) { for($i = 0; $i < 100; $i++){ $this->get_randcolor(); imagesetpixel($this->im, rand()%100, rand()%100, $this->randcolor); } } } // 添加干扰线 function set_ext_line () { if ($this->ext_line) { for($j = 0; $j < 2; $j++){ $rand_x = rand(2, $this->im_width); $rand_y = rand(2, $this->im_height); $rand_x2 = rand(2, $this->im_width); $rand_y2 = rand(2, $this->im_height); $this->get_randcolor(); imageline($this->im, $rand_x, $rand_y, $rand_x2, $rand_y2, $this->randcolor); } } } /**创建验证码图像: * 建立画布(__construct函数) * 设置画布背景($this->set_bgcolor();) * 获取随机字符串($this->get_randnum ();) * 文字写到图片上(imagestring函数) * 添加干扰点/线($this->set_ext_line(); $this->set_ext_pixel();) * 输出图片 **/ function create () { $this->set_bgcolor(); $this->get_randnum (); for($i = 0; $i < $this->len; $i++){ $font = rand(4,6); $x = $i/$this->len * $this->im_width + rand(1, $this->len); $this->get_y(); $this->get_randcolor(); imagestring($this->im, $font, $x, $this->y, substr($this->randnum, $i ,1), $this->randcolor); } $this->set_ext_line(); $this->set_ext_pixel(); header("content-type:image/png"); imagepng($this->im); imagedestroy($this->im); //释放图像资源 } }//end class /**使用验证码类的方法: * $an = new Authnum(验证码长度,图片宽度,图片高度); * 实例化时不带参数则默认是四位的60*25尺寸的常规验证码图片 * 表单页面检测验证码的方法,对比 $_SESSION[an] 是否等于 $_POST[验证码文本框ID] * 可选配置: * 1.验证码类型:$an->ext_num_type=1; 值为1是小写类型,2是大写类型,3是数字类型 * 2.干扰点:$an->ext_pixel = false; 值为false表示不添加干扰点 * 3.干扰线:$an->ext_line = false; 值为false表示不添加干扰线 * 4.Y轴随机:$an->ext_rand_y = false; 值为false表示不支持图片Y轴随机 * 5.图片背景:改变 $red $green $blue 三个成员变量的值即可 **/ $an = new Authnum(); $an->ext_num_type=''; $an->ext_pixel = true; //干扰点 $an->ext_line = false; //干扰线 $an->ext_rand_y= true; //Y轴随机 $an->green = 238; $an->create(); ?>
Recommended study: "PHP video tutorial》
The above is the detailed content of What should I do if the php verification code remains unchanged?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
