Internal Server Error Header Location
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company
Php Header 500 Internal Server Error
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs php header 404 Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why is header() causing an internal server error? up vote 0 down vote favorite I cannot figure out what could be causing this error. My Apache log is not recording any errors in the access log or error log regarding the page, yet somehow whenever I uncomment the header() line I get a 500 Internal Server Error. It can't be coming from PHP's fatal error when content is outputted before header() is called, that wouldn't cause a 500 would it? header("Location: /offices/page-".ceil($cache->size() / 15)); I tested $cache->size() and it's returning 22, so it should append a 2 to the end of the string and redirect. I did have ob_start() called before the header() but I tried calling ob_end_clean() right before it and it still did nothing... I even tried putting header("Location: /offices"); at the very beginning of the file and it still gives me a 500. php apache redirect share|improve this question asked Mar 1 '10 at 5:19 animuson♦ 33.5k2192124 add a comment| 3 Answers 3 active oldest votes up vote 2 down vote accepted The script continues to execute after your header() call. You need put exit; immediately after it. This shouldn't cause a 500 error, though. Edit: Evidently this worked - meaning your problem is probably in some related code further down the page? share|improve this answer edited Mar 1 '10 at 5:34 answered Mar 1 '10 at 5:28 jasonbar 8,99812642 1 Adding exit fixed the problem... –animuson♦ Mar 1 '10 at 5:33 1 If uncommenting header() was the only other change and this fixed it then weird. –jasonbar Mar 1 '10 at 5:35 add a comment| up vote 2 down vote Try to use a fully formed URL: header("Location: http://{$_SERVER['HTTP_HOST']}/offices/page-".ceil($cache->size() / 15)); share|improve this answer edited Mar 1 '10 at 5:34 answered Mar 1 '10 at 5:25 deceze 303k44386530 1 I tried putting in header("Location: http://www.example.com"); still 500 error. –animusonϗ
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 http://stackoverflow.com/questions/2354026/why-is-header-causing-an-internal-server-error million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up PHP header location redirect causing 500 Internal Server error up vote -1 down vote favorite I I keep getting a 500 Internal Server Error when the script below reaches the header('location:php_email_thankyou.php'). Im not sure what is causing this, http://stackoverflow.com/questions/2797751/php-header-location-redirect-causing-500-internal-server-error as I can place the header expression before or after the if statements and it works fine. In firebug it mentions a GET request for the php_email_thankyou.php page not sure if that means anything... clean($_POST); if (isset($validation['send'])) { header('location:php_email_thankyou.php'); exit(); } else { print json_encode($validation); exit(); } } else { $validation = $val->clean($_POST); } } ?> Thanks heaps! php ajax redirect header server-error share|improve this question asked May 9 '10 at 13:28 Globalz 1,22842035 Are you sure it's not the target file causing the server error? –Pekka 웃 May 9 '10 at 13:30 Plus, can you look into your server's error logs? They will contain an explanation why the 500 happened. –Pekka 웃 May 9 '10 at 13:30 Try to manually type in the url o
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring http://stackoverflow.com/questions/4162223/how-to-send-500-internal-server-error-error-from-a-php-script developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to send 500 Internal Server Error error from a PHP script up vote 52 down vote favorite 18 I need to send "500 Internal Server Error" from an PHP script under certain internal server conditions. The script is supposed to be called by a third party app. The script contains a couple of die("this happend") statements for which I need to send the 500 Internal Server Error response code instead of the usual 200 OK. The third party script will re-send the request under certain conditions which include not receiving the 200 OK response code. Second part of the question: I need to setup my script like this: I need to send 200 header only after the last line has been executed. Edit A side question: can I send strange 500 headers such as these: HTTP/1.1 500 No Record Found HTTP/1.1 500 Script Generated Error (E_RECORD_NOT_FOUND) HTTP/1.1 500 Conditions Failed on Line 23 Will such errors get logged by the webserver? php header http-headers share|improve this question edited Nov 19 '15 at 1:33 pnuts 33.9k63769 asked Nov 12 '10 at 6:40 Salman A 122k44259337 is not doable when u sent header and remove header later –ajreal Nov 12 '10 at 7:39 add a comment| 6 Answers 6 active oldest votes up vote 124 down vote accepted header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500); share|improve this answer answered Nov 12 '10 at 6:47 Core Xii 4,10442037 FYI, this solution sends the X-Pad: avoid browser bug header in some versions of Apache. stackoverflow.com/questions/8711584/… . http_response_code() omits this header. –Anthony Rutledge Jun 4 '15 at 12:44 1 That even works if the header isn't at the beginning, (such as a proof of working), good job. –i am me Nov 30 '15 at 19:56 add a com