views:

133

answers:

2

Hi dear stackers :P

Thanks to this forum, I learnt PHP header function does not actually send header to Apache server but only to the client.

What I wanna do is to generate an error 500, and let Apache displays its corresponding page. Is there a way to force it ?

Thanks in advance ! (and allez les bleus !)

+2  A: 

Do a redirect to a URL that causes a 500.

For example a url with an invalid .htaccess directive.

zaf
thanks, I'll try that right now !
Rolf
I tried to put in the .htaccess at the fileRewriteRule ^error\.php$ /force_error_500.php [NC,R=500](force_error_500.php does not exist)header('Location:error.php'); causes only a 404... I guess I missed a point :(
Rolf
Yes... create an INVALID .htaccess file. Yours was a valid one :)
zaf
sorry, sorry, sorry...now I have this:RewriteRule ^error\.php$ /stupid_directive.php [YMCA]on every URL I go, I got a 500... but I'd like to get it only with www.mysite.com/error.php...
Rolf
OK, create a directory and put the invaild htaccess in there. In error.php just redirect to that directory.
zaf
thanks, it works :)
Rolf
+1  A: 

There's a way of sending a 500 Error to the browser, but you'll have to provide the page yourself:

<?php
header('HTTP/1.1 500 Internal Server Error');
echo <<<ERRORTEXT
The server encountered an unexpected condition which prevented it 
from fulfilling the request.
ERRORTEXT;
// also notify server operator, maybe?
exit;
?>
Piskvor
thanks for your reply, but I need to use Apache error pages...
Rolf