代码点火器:弹出消息后无法重定向


Codeigniter: unable to redirect after popup message

echo '<script>alert("Your session has timeout, please relogin again!");</script>'; 
            redirect('main/login', 'refresh');

这是错误:

A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/swtwnonu/public_html/ignite_project/application/controllers/member.php:19)
Filename: helpers/url_helper.php
Line Numer: 540

我想将这个人重定向到我的主/登录页面,在他为我显示的消息单击确定之后,但是我不知道为什么会发生错误。请帮忙!

重定向使用 HTTP 标头工作,这些标头不能在任何输出(文本、HTML、不可见字符、Javascript 等(之后发送。

如果您使用 Javascript 打印消息,无论如何都可以使用它进行重定向:

echo '<script>alert("Your session has timeout, please relogin again!"); window.location.replace = ''index.php/main/login''; window.location.href = ''index.php/main/login'';</script>';

您也可以使用 HTML <meta /> 标记来执行此操作:

<meta http-equiv="refresh" content="0; url=index.php/main/login" />

此标签将在加载网站后立即重定向,您可以更改重定向前等待的任何值(以秒为单位(的0