如果发送了标头,如何重定向? [英] How to redirect if the header is been sent?
本文介绍了如果发送了标头,如何重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 wordpress,不幸的是,我必须在后端工作.我需要在发送 CMS 标头后打印有关用户操作的消息.
I use wordpress and unfortunately, I have to work behind the backend. I need to print message about user action while the CMS header has been sent.
除了使用 javascript 之外,还有其他选择吗?我更喜欢 PHP 解决方案.
Is there any alternative than using javascript? I prefer a PHP solution.
echo '<script type="text/javascript">/* <![CDATA[ */';
echo 'window.location.href = "'. $redirect_url . '";';
echo '/* ]]> */</script>';
推荐答案
您可以使用查询字符串传递消息:
You can pass the message by using query string:
header('location: index.php?msg=1');exit;
并使用 swich 根据 msg
查询字符串 var 的值显示消息:
And use swich to show the message based on value of msg
query string var:
switch($_GET['msg'])
{
case: 1; // do foo
case: 2; // do bar
case else : ; // ooops
}
这篇关于如果发送了标头,如何重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文