BioBob Posted August 5, 2008 Share Posted August 5, 2008 I seem to be at a loss for a resolution on why a very simple script wont work. I tore out the rest of my code and found that header() just isnt working. So the simplest form of my script is this: <?php header("HTTP/1.1 404 Not Found"); //header("HTTP/1.0 404 Not Found"); //also not working //header("Status: 404 Not Found"); //el nada! ?> Running Windows XP SP2/3, php 5.2.6, in ISAPI mode. Need it for the speed. I've ripped out everything php and completely reinstalled IIS, and for spite tried installing in FastCGI mode and CGI mode. I think FastCGI is my best bet but that install had the exact same problems, CGI does seem to fix this issue, however I cant use it cuz I need it in ISAPI for the speed, as I said. I've ripped it down to the bare bones. No extensions installed, swapped my ini files for both dist and recommended, ran the installer, tried manual install, even tried downgrading to 5.2.5 and 5.2.3 neither with any success. Ok, WTF? Well let me see if it is actually sending out headers then... Went to web-sniffer.net to get a quick header list (the headers_list() and headers_sent() functions also dont show jack has been sent), and get this back: HTTP Request Header Connect to *.*.*.* on port 80 ... ok GET /404test.php HTTP/1.0[CRLF] Connection: close[CRLF] User-Agent: Web-sniffer/1.0.27 (+http://web-sniffer.net/)[CRLF] Accept-Encoding: gzip[CRLF] Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7[CRLF] Cache-Control: no[CRLF] Accept-Language: de,en;q=0.7,en-us;q=0.3[CRLF] Referer: http://web-sniffer.net/[CRLF] [CRLF] HTTP Response Header Name Value Delim HTTP Status Code: HTTP/1.1 404 Not Found Server: Microsoft-IIS/5.1 Date: Tue, 05 Aug 2008 07:27:35 GMT Content-type: text/html Ok, so apparently it IS pumping out the headers right. Um, I guess if you can call that working right. But before you ask what the deal is, I'll explain further. IE7 had the Show Friendly HTTP Errors option stripped out. Fine big deal. Checked this against an old system, and get the same crap. 3 different boxes. Now what the big deal is, is that Im actually getting HTML coming back at me instead of just a 404 page, not even a customized 404 page, it gives the following: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD> <BODY></BODY></HTML> Only other time I have seen this is just running "<?php ?>" so uh, well hell, I even tried it for part of what else I was gonna use header() for, images, and php does appear to correctly pump out jpg contents (as if image.php was actually an image, contents loaded from readfile($file) and file_get_contents($file) ). I've even tried output buffering, well kind of have to workin with jpgs, but even that didnt help. Essencially, for a touch of privacy, users that arent logged in would just get a 404 page, not a customized 404, but logged in users could see the contents... So I just dont get it. It looks like its not a server problem because as far as I can tell the header is sent (then get the extra HTML junk that shouldnt be there), its not a browser problem, tried teh script on other servers, 2000, 2k3, works fine, so not a script problem, browser issue doesnt make sense cuz the other servers serve these right, and when I browse to the problem server with their browsers (firefox, opera) their scripts work right on their browsers but get teh same extra html junk in them hitting the problem server, not a firewall issue, the solution is just above my head... Suggestions? Im open to anything at this point. Well, excluding things that require a 9 iron, jar of peanut butter, and a moose... Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/ Share on other sites More sharing options...
ignace Posted August 5, 2008 Share Posted August 5, 2008 a 9 iron, jar of peanut butter, and a moose... ??? Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-608544 Share on other sites More sharing options...
BioBob Posted August 6, 2008 Author Share Posted August 6, 2008 Ok tried giving the peanut butter to the moose and I think it got mad at me because it was chunky not creamy and attempted to assault me with the nine iron. Next time I'll have to use a stuffed moose for safety. So, no suggestions on what would cause header('HTTP 1.1 404 Not Found"); to pump out HTML on an IIS server in ISAPI mode only? Even using all default .ini settings? Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609082 Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 Just sending the header tells the browser "Okay the page failed", but then you continue to echo HTML and such. It's your responsibility to include the 404 page. Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609114 Share on other sites More sharing options...
BioBob Posted August 6, 2008 Author Share Posted August 6, 2008 Displaying the html is what I want to stop it from doing! <?php header('HTTP/1.0 404 Not Found'); ?> Thats the whole script! Where or why the hell am I getting: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD> <BODY></BODY></HTML> Do you see anywhere in the php part of the script where Im telling it to display this? Im not including, Im not echo'ing printing, im not doing ANYTHING! But I did try like you said to provide the 404 page. I changed IIS's custom error msgs to display an html page that just says "Object Not Found" but when I hit the header script, it shows that HTML I put above. I dont want that HTML above, I want "Object Not Found" to be displayed. Why on earth is it doing this? Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609257 Share on other sites More sharing options...
kenrbnsn Posted August 6, 2008 Share Posted August 6, 2008 Put an "exit()" after the header() Ken Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609264 Share on other sites More sharing options...
BioBob Posted August 6, 2008 Author Share Posted August 6, 2008 Great idea! <?php header("404 something..); exit(); ?> Doesnt work! Im really thinking this is a bug in php in ISAPI mode, as it works normally in CGI (but I cant use CGI mode), this behavior is not normal at all! Now what I get is a big fat empty page, but not a 404 or redirected to 404... Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609285 Share on other sites More sharing options...
BioBob Posted August 6, 2008 Author Share Posted August 6, 2008 Double post. Sue me. After googling all freakin night, I came across this: ; if cgi.nph is enabled it will force cgi to always sent Status: 200 with ; every request. cgi.nph = 0 Makes sense that would cause the problem, but alas, it did not. Nor did ; cgi.rfc2616_headers configuration option tells PHP what type of headers to ; use when sending HTTP response code. If it's set 0 PHP sends Status: header that ; is supported by Apache. When this option is set to 1 PHP will send ; RFC2616 compliant header. ; Default is zero. cgi.rfc2616_headers = 1 ... Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609361 Share on other sites More sharing options...
Third_Degree Posted August 6, 2008 Share Posted August 6, 2008 Weird, I have almost no experience with IIS (did one site on it), but it seems it automatically outputs this HTML for some reason. Try other HTTP headers? header('HTTP/1.1 410 Gone'); Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609368 Share on other sites More sharing options...
BioBob Posted August 6, 2008 Author Share Posted August 6, 2008 Yeah I tried a bunch of other headers and versions of them too. like header('Status: 404 or 403, I went thru a bunch and they all seem to do the same thing. Only thing I can get to work is header('Location: www.... . Thing that still kills me is when i try to analyze the headers sent with the various plethora of tools on the web, they all seem to report the same thing, and that is that the header IS going out. None of them seem to report that 200 is being sent at all, the behavior is like it is tho. But even checked on multiple computers hitting my problem server and they all behave the same way. Is it possible that in ISAPI mode, somehow I have an extra character or something that doesnt show that could cause this kind of behavior, like a vertical tab or 0x00, 0x01 or something? Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609377 Share on other sites More sharing options...
BioBob Posted August 6, 2008 Author Share Posted August 6, 2008 #1 Server Response: http://*.*.*.*/notfound.php HTTP Status Code: HTTP/1.1 410 Gone Server: Microsoft-IIS/5.1 Date: Wed, 06 Aug 2008 07:07:05 GMT X-Powered-By: PHP/5.2.6 Content-type: text/html Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609387 Share on other sites More sharing options...
LemonInflux Posted August 6, 2008 Share Posted August 6, 2008 Erm..As I understand it, a 404 header only tells the browser the page is wrong, not what to show instead. Why not build a 'page not found' code and stick it underneath? ---------------- Now playing: Enter Shikari - Return To Energiser (Zane Lowe BBC Session) via FoxyTunes Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609488 Share on other sites More sharing options...
BioBob Posted August 6, 2008 Author Share Posted August 6, 2008 I think thats what Im gonna have to do. The thing that concerned me is that I am going to have content that does expire after periods of time and not just using the 404 but like 403 or no longer available and other headers to make sure certain pages do not get cached in search engines. Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609500 Share on other sites More sharing options...
LemonInflux Posted August 6, 2008 Share Posted August 6, 2008 Have separate headers telling the browser not to cache the page as well then ---------------- Now playing: Flyleaf - Cassie via FoxyTunes Quote Link to comment https://forums.phpfreaks.com/topic/118223-problem-with-header/#findComment-609503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.