标头(“位置")会导致[500]内部服务器错误? [英] header("location") causes [500] internal server error?

查看:60
本文介绍了标头(“位置")会导致[500]内部服务器错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是什么原因导致此错误.我的Apache日志未在有关该页面的访问日志或错误日志中记录任何错误,但是无论如何,无论何时取消注释header()行,都会收到500 Internal Server Error.在调用header()之前输出内容时,它不可能来自PHP的致命错误,那不会导致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));

我测试了$cache->size(),它返回22,因此应在字符串末尾附加2并重定向.我确实在header()之前调用过ob_start(),但是我尝试在它之前调用ob_end_clean(),但它仍然无济于事...

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...

我什至尝试将header("Location: /offices");放在文件的开头,但仍然可以得到500.

I even tried putting header("Location: /offices"); at the very beginning of the file and it still gives me a 500.

推荐答案

调用header()后,脚本继续执行.您需要在其后立即放置exit;.不过,这不应引起500错误.

The script continues to execute after your header() call. You need put exit; immediately after it. This shouldn't cause a 500 error, though.

显然这可行-这意味着您的问题可能出在页面下方的一些相关代码中?

Evidently this worked - meaning your problem is probably in some related code further down the page?

这篇关于标头(“位置")会导致[500]内部服务器错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆