Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 验证码图片不显示

验证码图片不显示

Jun 23, 2016 pm 01:40 PM

本人不会PHP,所以还请各位大神见谅
直接访问这个页面也不显示(红色XX)
本人百度试着解决
GD是开着的
可还是不显示图片
求大神帮助

<?phpini_set('display_errors', 'Off');Header("Content-type: image/gif");/** 初始化*/$border = 0; //是否要边框 1要:0不要$how = 4; //验证码位数$w = $how*15; //图片宽度$h = 20; //图片高度$fontsize = 5; //字体大小$alpha = "abcdefghijkmnopqrstuvwxyz"; //验证码内容1:字母$number = "023456789"; //验证码内容2:数字$randcode = ""; //验证码字符串初始化srand((double)microtime()*1000000); //初始化随机数种子	$im = ImageCreate($w, $h); //创建验证图片/** 绘制基本框架*/$bgcolor = ImageColorAllocate($im, 255, 255, 255); //设置背景颜色ImageFill($im, 0, 0, $bgcolor); //填充背景色if($border){    $black = ImageColorAllocate($im, 0, 0, 0); //设置边框颜色    ImageRectangle($im, 0, 0, $w-1, $h-1, $black);//绘制边框}/** 逐位产生随机字符*/for($i=0; $i<$how; $i++){       $alpha_or_number = mt_rand(0, 1); //字母还是数字    $str = $alpha_or_number ? $alpha : $number;    $which = mt_rand(0, strlen($str)-1); //取哪个字符    $code = substr($str, $which, 1); //取字符    $j = !$i ? 4 : $j+15; //绘字符位置    $color3 = ImageColorAllocate($im, mt_rand(0,100), mt_rand(0,100), mt_rand(0,100)); //字符随即颜色    ImageChar($im, $fontsize, $j, 3, $code, $color3); //绘字符    $randcode .= $code; //逐位加入验证码字符串}/** 添加干扰*/for($i=0; $i<5; $i++)//绘背景干扰线{       $color1 = ImageColorAllocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); //干扰线颜色    ImageArc($im, mt_rand(-5,$w), mt_rand(-5,$h), mt_rand(20,300), mt_rand(20,200), 55, 44, $color1); //干扰线}   for($i=0; $i<$how*40; $i++)//绘背景干扰点{       $color2 = ImageColorAllocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); //干扰点颜色     ImageSetPixel($im, mt_rand(0,$w), mt_rand(0,$h), $color2); //干扰点}//把验证码字符串写入sessionsession_start();$_SESSION["usimga"] = $randcode;/*绘图结束*/Imagegif($im);ImageDestroy($im);/*绘图结束*/?> 
Copy after login


回复讨论(解决方案)

代码本身没有问题
请检查是否有 BOM 头

代码本身没有问题
请检查是否有 BOM 头


大神,不懂啊
怎么查看

代码本身没有问题
请检查是否有 BOM 头


查看了,没有bom头
还有其他的可能出问题的地方吗
大神们
求帮助

echo base64_encode(file_get_contents('http://localhost/你的程序文件名'));

贴出结果

echo base64_encode(file_get_contents('http://localhost/你的程序文件名'));

贴出结果



IA0K 运行是这个

不个能!
图片只有3个字节长?

不个能!
图片只有3个字节长?


chrome监控
response 的content-length确实是3
我也不知道哪里有问题
研究了一天了

IA0K 是 空格回车换行 的 base64 编码
如果输出是以 IA0K 开头的话,就表示你的程序开始处有这些字符,请删除
如果是仅有 IA0K 的话,那就是你把程序文件名搞错了

IA0K 是 空格回车换行 的 base64 编码
如果输出是以 IA0K 开头的话,就表示你的程序开始处有这些字符,请删除
如果是仅有 IA0K 的话,那就是你把程序文件名搞错了



<?phpecho base64_encode(file_get_contents('http://www.bz798.com/usimg.php'));?> 
Copy after login


这是站点目录下的testbom.php文件
usimg.php是验证码文件
通过testbom监测 content-length是3
通过站点本身访问 比如刷新验证码 content-length也是3
通过直接访问usming 还是3

IA0K 是 空格回车换行 的 base64 编码
如果输出是以 IA0K 开头的话,就表示你的程序开始处有这些字符,请删除
如果是仅有 IA0K 的话,那就是你把程序文件名搞错了



程序本身应该是没有问题的
因为据说之前的php环境是可以显示的
现在php环境是重新搭建的
可能是php配置的问题
GD是开着的
用的是IIS的FAST-CGI
session-cache是nocache(也许这里有问题,因为chrome会报ERR_CACHE_MISS这样一个错误,大神如果方便的话可以访问一下站点,在netwrok监控里会报一个错误)
别的原因,因为我不懂php,所以也不知道了

IA0K 是 空格回车换行 的 base64 编码
如果输出是以 IA0K 开头的话,就表示你的程序开始处有这些字符,请删除
如果是仅有 IA0K 的话,那就是你把程序文件名搞错了



netwrok监控报的错误是这样的

这个是请求被取消吗?

换个浏览器试试。

有没有大神帮助解决问题

换个浏览器试试。



IE里没有ERR_CACHE_MISS这个错误
但是还有

这个问题没人能解决吗

print_r(get_headers('http://www.bz798.com/usimg.php'));
Copy after login
Array(    [0] => HTTP/1.1 200 OK    [1] => Cache-Control: private, max-age=10800, pre-check=10800    [2] => Content-Type: image/gif    [3] => Expires: Thu, 19 Nov 1981 08:52:00 GMT    [4] => Last-Modified: Sat, 10 Jan 2015 17:55:26 GMT    [5] => Server: Microsoft-IIS/7.5    [6] => X-Powered-By: PHP/5.2.8    [7] => Set-Cookie: PHPSESSID=huf628licrq4t5bdd0mtuor2s6; path=d:\php\phpsession\    [8] => X-Powered-By: ASP.NET    [9] => Date: Sun, 11 Jan 2015 08:19:47 GMT    [10] => Connection: close    [11] => Content-Length: 3)
Copy after login

显然执行的是一个空文件

你把程序换个名字再试一下

还有就是把 
ini_set('display_errors', 'Off');
Header("Content-type: image/gif");
都去掉



Notice:  A session had already been started - ignoring session_start() in D:\web\legou\usimg.php on line 54


用notepad打开你的图片是这样的。
很明显,是session_start()之前有其他输出或者空白。

去掉空白后,图片是正常的:

还有就是session_start()是放在代码的最



Notice:  A session had already been started - ignoring session_start() in D:\web\legou\usimg.php on line 54


用notepad打开你的图片是这样的。
很明显,是session_start()之前有其他输出或者空白。

去掉空白后,图片是正常的:




上面说错了。是由于session_start被重复执行了。关闭错误提示应该就可以了。

另存文件为utf-8无bom头

多谢这么多人指点,我把生成的验证码图片格式改成png,然后就可以了,虽然不知道怎么回事

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

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 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)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles