Header()不重定向PHP [英] Header() is not redirecting PHP
问题描述
我正在使用以下PHP代码来检查会话。但如果会话未登录,则页面不重定向只显示黑页。
I am using following PHP code to check session. But if the session is not logged into then page is not redirect just show the black page.
我的条件是对的!它击中了标题函数..
这是我的代码:
My If condition is right ! it is hitting header function .. Here is my code:
if(
!isset($_SESSION['SESS_MEMBER_ID'])
|| (trim($_SESSION['SESS_MEMBER_ID']) == '')
AND !isset($fb_login)
) {
header("location:login.php?msg=Please+Login+Again.");
}
建议欢迎!
HTTP/1.1 200 OK
Date: Wed, 10 Oct 2012 10:57:14 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
推荐答案
如果您正在使用 header(Location:);
输出内容后请确保先放入 ob_start();
在脚本中。 ob_start();
缓冲你的脚本,所以在你调用 ob_end();
或结束之前不输出任何内容到达文件。在内容输出到浏览器后调用标题(位置:);
可能会导致问题。
If you're using header("Location: ");
after you've output content make sure you've put ob_start();
earlier in the script. ob_start();
buffers your script, so nothing is output until you either call ob_end();
or the end of the file is reached. Calling header("Location: ");
after content has already been output to the browser can cause problems.
这篇关于Header()不重定向PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!