标题(“位置”)导致[500]内部服务器错误?
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.
我无法弄清楚导致此错误的原因。 我的Apache日志没有记录关于页面的访问日志或错误日志中的任何错误,但是当我取消注释 我测试了 我甚至尝试将 header() code>行时,我得到500内部服务器错误。 在调用
header() code>之前输出内容时,它不能来自PHP的致命错误,这不会导致500吗? p>
header(“Location:/ offices / page - ”。ceil($ cache-> size()/ 15));
code> pre>
$ cache-> size() code>并且它返回22,所以它应该在字符串的末尾添加2并重定向。 我确实在
header() code>之前调用了
ob_start() code>,但我尝试在它之前调用
ob_end_clean() code>,但它仍然没有做任何事情。 。 p>
标题(“Location:/ offices”); code>放在文件的最开头,它仍然给我一个500。 p>
div>
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?
Try to use a fully formed URL:
header("Location: http://{$_SERVER['HTTP_HOST']}/offices/page-".ceil($cache->size() / 15));
I had the same thing going on. After repeatedly banging my head on the monitor, it isn't the header("Location: myPage.php"); line that is broken - it is myPage.php that is broken! Try redirecting to another page. I hope I save someone else time
Another reason might be - you need to remove space after location
:
header("location :
header("location:
If that's not your problem, then try to check the php & apache error logs.