A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearPHP 404 error page won't display content - page 1
User InfoPosts
PHP 404 error page won't display content#1
I(m having a problem implementing custom 404 error pages on my Windows/IIS/PHP webhost. Whenever I try to send the 404 status message in the header, no content is sent to the client and a blank page is displayed instead.

Here is a very simple script I(m using:

header((HTTP/1.1 404 Not Found();
header((Status: 404 Not Found();

On my dev machine the output (displayed in a browser) is

array(2) { [0]=>  string(23) "X-Powered-By: PHP/5.2.6" [1]=>  string(21) "Status: 404 Not Found" }

On my host there is no output. I can(t seem to generate anything but a blank page regardless of what content is echoed by PHP, or included below as normal HTML, though PHP processing e.g. logging, database writes etc continue as normal.

Can anyone suggest what the problem might be or how to resolve it?

posted date: 2009-04-13 06:27:00

Re: PHP 404 error page won't display content#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-13 06:27:01

Re: PHP 404 error page won't display content#3
What if you put text after the PHP tags?Also, make sure your script isn(t erroring out on your host, whether checking apache error logs, running php -l on your script or turning error_reporting on and display_errors on.

posted date: 2009-04-13 06:29:00

Re: PHP 404 error page won't display content#4
As you suggested, I've changed the code to: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); var_dump(headers_list()); ?>CONTENT The output is still blank on my host.

posted date: 2009-04-13 06:37:00

Re: PHP 404 error page won't display content#5
Try commenting out 1 line at a time until you see "CONTENT" outputted

posted date: 2009-04-13 06:40:00

Re: PHP 404 error page won't display content#6
(blank page( smells like error_reporting(0) hiding the error messages you would get. Maybe there is some output before your headers and that raises an error. Check that.

posted date: 2009-04-13 07:47:00

Re: PHP 404 error page won't display content#7
If PHP is configured at your host to run through CGI, it may be impossible to generate 404 error pages in IIS (except by lying and returning 200 OK, which is a Bad Thing). Certainly I(ve been unable to persuade IIS 4-6.0 to allow my CGI 404 errors through to browsers.You generally don(t want PHP to run CGI anyway, there are other related problems as well as it being slow. On IIS, the PHP ISAPI extension should be preferred (though as I(ve not tried it I can(t confirm it solves this specific problem).

posted date: 2009-04-13 08:31:00

Re: PHP 404 error page won't display content#8
Are you getting this same result on Firefox AND IE? If not, I may know the answer

posted date: 2009-04-13 08:52:00

Re: PHP 404 error page won't display content#9
Check that your host allows you to change headers on the fly with PHP. My host doesn(t allow me to set the 404 header through PHP, though other headers (301, content-type) are fine.

posted date: 2009-04-13 12:01:00

Re: PHP 404 error page won't display content#10
My advice is to not set the HTTP/1.1 404 header yourself and let the web server do it for you.Traditionally, this is done through the Status header, which the web server should take and turn into an HTTP/1.0 or 1.1 404 Not Found header.(Side Note: The Status header is not a real HTTP header and is used solely to communicate information from an app to the server itself.)

posted date: 2009-04-13 12:21:00

Re: PHP 404 error page won't display content#11
+1, sounds dumb but seen this several times and should be the first thing checked

posted date: 2009-04-15 07:28:00

Re: PHP 404 error page won't display content#12
I have the same problem with PHP 5.2.6 on Linux. I find that the first 8109 bytes are not printed by the web server.IE6 ignores custom error pages < 512 bytes in length. This could be an explanation for this problem, but probably you have tested in more than one browser anyway.

posted date: 2009-08-20 00:14:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.