yzerman Posted March 4, 2007 Share Posted March 4, 2007 Sample of code: if (defined('constant')) { // show content } else { header("HTTP/1.1 404 Not Found"); } ok, what I am trying to do is, use files as includes from my index page where the constant is defined. What I want to happen is if a user trys to goto blah.php directly, instead of /index.php?page=blah they receive a 404 error, and are sent to the 404 file not found page. What I am actually getting is a blank white page. What am i doing wrong? Link to comment https://forums.phpfreaks.com/topic/41094-solved-headers-no-its-not-what-you-think/ Share on other sites More sharing options...
Orio Posted March 4, 2007 Share Posted March 4, 2007 I don't know if that will make any difference, but try this: header("HTTP/1.0 404 Not Found"); Also, when are you getting the white page- when you are accessing directly or when you are going through the index? Orio. Link to comment https://forums.phpfreaks.com/topic/41094-solved-headers-no-its-not-what-you-think/#findComment-198998 Share on other sites More sharing options...
yzerman Posted March 4, 2007 Author Share Posted March 4, 2007 @Orio, no that does not make a differance. (1.0 vs 1.1) and for your other question, when I access directly. I have temporarily made it redirect directly to my 404 error page, but this isn't what I want. Link to comment https://forums.phpfreaks.com/topic/41094-solved-headers-no-its-not-what-you-think/#findComment-199019 Share on other sites More sharing options...
Orio Posted March 4, 2007 Share Posted March 4, 2007 This is driving me nuts. I've got the same problem, and I can't figure it out... I found this in the manual, but it didn't work for me. You can try it yourself: If this doesn't work: <?php header("HTTP/1.0 404 Not Found"); ?> You should set option cgi.rfc2616_headers in php.ini. If you can't, use this: <?php function header_status($status) { // 'cgi', 'cgi-fcgi' if (substr(php_sapi_name(), 0, 3) == 'cgi') header('Status: '.$status, TRUE); else header($_SERVER['SERVER_PROTOCOL'].' '.$status); } header_status('404 Not Found'); ?> See also http://bugs.php.net/bug.php?id=27345 Orio. Link to comment https://forums.phpfreaks.com/topic/41094-solved-headers-no-its-not-what-you-think/#findComment-199027 Share on other sites More sharing options...
shoz Posted March 4, 2007 Share Posted March 4, 2007 The message that you usually see when there is a 404 error is generated by Apache. If you send the 404 header using PHP then you should also generate an HTML message to notify the user. You can copy the HTML 404 message to give users an identifcal message. If you can, you should also put the include files outside of the "Document Root". If you have them in a directory of their own you should be able to use a .htaccess file to protect the files as well. Order deny,allow Deny from all Link to comment https://forums.phpfreaks.com/topic/41094-solved-headers-no-its-not-what-you-think/#findComment-199134 Share on other sites More sharing options...
Orio Posted March 4, 2007 Share Posted March 4, 2007 The message that you usually see when there is a 404 error is generated by Apache. If you send the 404 header using PHP then you should also generate an HTML message to notify the user. You can copy the HTML 404 message to give users an identifcal message. If you can, you should also put the include files outside of the "Document Root". If you have them in a directory of their own you should be able to use a .htaccess file to protect the files as well. Order deny,allow Deny from all Yeah, I use the .htaccess trick alot when I want files available only for php scripts (or ftp). At least now I understand why I didn't get the 404 when I sent the headers, thanks shoz Orio. Link to comment https://forums.phpfreaks.com/topic/41094-solved-headers-no-its-not-what-you-think/#findComment-199138 Share on other sites More sharing options...
yzerman Posted March 4, 2007 Author Share Posted March 4, 2007 The message that you usually see when there is a 404 error is generated by Apache. If you send the 404 header using PHP then you should also generate an HTML message to notify the user. You can copy the HTML 404 message to give users an identifcal message. If you can, you should also put the include files outside of the "Document Root". If you have them in a directory of their own you should be able to use a .htaccess file to protect the files as well. Order deny,allow Deny from all Alright, so basically redirecting them to my default 404 page should work then. Appreciate the help. Link to comment https://forums.phpfreaks.com/topic/41094-solved-headers-no-its-not-what-you-think/#findComment-199467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.