如何在已发送标头后跳转到其他页面?
我有一些代码写在我的模板文件,我想使用php跳转到其他页面时,某些条件是真的,但我不能在这里使用头命令,因为标题信息已发送到其他php文件之前,这个模板文件。那我现在怎么能跳到其他网址呢?只有使用js的方式?
Warning: Cannot modify header information - headers already sent by ...发布于 2013-10-04 02:37:15
使用输出缓冲和头清除来实现这一点。
ob_start()
...
if (!headers_sent()) {
foreach (headers_list() as $header)
header_remove($header);
}
ob_flush_end()还没经过测试,但试试看。
发布于 2013-10-04 02:39:47
你有两个选择。
a/使用javascript
window.location = "http://www.yoururl.com";b/使用元
<META http-equiv="refresh" content="5;URL=http://www.yourlink.com/new-link">发布于 2013-10-04 02:44:31
CP510的分析器很好。另一种方法是使用javascript重定向页面。引用Ryan McGeary answer的话,您可以这样做
// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");
or
// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";https://stackoverflow.com/questions/19172271
复制相似问题