开发者

header("location") causes [500] internal server error?

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.


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.


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


I literally had the same problem,but it seems that I wrote header("Location : page.php")instead of header("Location: page.php");. YES that one space makes a difference!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜