解决php session验证码不现实的有关问题
解决php session验证码不现实的问题
本人一开始图片老显示不出来,显示的是一个裂了的图片,经查询发现可能由以下几种可能造成
1)在header("Content-type:image/png");前加如下一段代码
ini_set('display_errors', 'Off');
附上生成验证码的图片的代码
<?php ini_set('display_errors', 'Off'); header("Content-type:image/png"); session_start(); $_SESSION['code'] = 'null'; //初始化 $width = '58'; $height = '22'; //$code = ''; $tmptext =''; $bordercolor= ''; for($i=0;$i<4;$i++) { $tmptext = rand(0,9); $code .= $tmptext; } $_SESSION['code'] = $code; //以下三句诗让浏览器不缓存 @header("Expires:-1"); @header("Cache-Control:no-store,private,posc-check=0,pre-check=0,max-age=0",FALSE); @header("Pragma:no-cache"); if(function_exists('imagecreate') && function_exists('imagecolorset') && function_exists('imagecopyresized') && function_exists('imagecolorallocate') && function_exists('imagesetpixel') && function_exists('imagechar') && function_exists('imagecreatefromgif') && function_exists('imagepng') ) { $im = imagecreate($width, $height); $backgroundcolor = imagecolorallocate($im, 255, 255, 255); $numorder = array(1,2,3,4); /**shuffle将数组打乱*/ shuffle($numorder); /**array_flip返回一个被反转的数组,键值被处理值*/ $numorder = array_flip($numorder); $x=''; $y=''; $text_color = ''; for($i=1;$i<=4;$i++) { $x = $numorder[$i] * 13 + mt_rand(0,4) -2; $y = mt_rand(0,3); $text_color = imagecolorallocate($im, mt_rand(50,255), mt_rand(50,255), mt_rand(50,255)); /**将字符画在$im图中,5表示字体的大小 $x+5 */ imagechar($im, 5, $x+5, $y+3, $code[$numorder[$i]], $text_color); } $linenums = mt_rand(10,32); for($i=0;$i<=$linenums;$i++) { $linecolor = imagecolorallocate($im, 255, mt_rand(0,255), mt_rand(0,255)); $linex = mt_rand(0,255); $liney = mt_rand(0,255); imageline($im, $linex, $liney, $linex+mt_rand(0,4)-2, $liney+mt_rand(0,4)-2, $linecolor); } for($i=0;$i<40;$i++) { $pointcolor = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); imagesetpixel($im, mt_rand(0,$width), mt_rand(0,$height), $pointcolor); } $bordercolor = imagecolorallocate($im, 150, 150, 150); imagerectangle($im, 0, 0, $width-1, $height-1, $bordercolor); imagepng($im); imagedestroy($im); }?>
2)变量没初始化
3)在header("Content-type:image/png");前加入
ob_clean();
第二三中方法不确保可以解决问题,仅供参考。

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

AI Hentai Generator
Generate AI Hentai for free.

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



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

Function means function. It is a reusable code block with specific functions. It is one of the basic components of a program. It can accept input parameters, perform specific operations, and return results. Its purpose is to encapsulate a reusable block of code. code to improve code reusability and maintainability.

In this article, we will learn about enumerate() function and the purpose of “enumerate()” function in Python. What is the enumerate() function? Python's enumerate() function accepts a data collection as a parameter and returns an enumeration object. Enumeration objects are returned as key-value pairs. The key is the index corresponding to each item, and the value is the items. Syntax enumerate(iterable,start) Parameters iterable - The passed in data collection can be returned as an enumeration object, called iterablestart - As the name suggests, the starting index of the enumeration object is defined by start. if we ignore

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Detailed explanation of the role and function of the MySQL.proc table. MySQL is a popular relational database management system. When developers use MySQL, they often involve the creation and management of stored procedures (StoredProcedure). The MySQL.proc table is a very important system table. It stores information related to all stored procedures in the database, including the name, definition, parameters, etc. of the stored procedures. In this article, we will explain in detail the role and functionality of the MySQL.proc table

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.

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?

The file_exists method checks whether a file or directory exists. It accepts as argument the path of the file or directory to be checked. Here's what it's used for - it's useful when you need to know if a file exists before processing it. This way, when creating a new file, you can use this function to know if the file already exists. Syntax file_exists($file_path) Parameters file_path - Set the path of the file or directory to be checked for existence. Required. Return file_exists() method returns. Returns TrueFalse if the file or directory exists, if the file or directory does not exist Example let us see a check for "candidate.txt" file and even if the file
