PHP /代码信号器 - 使用exit() [英] PHP/codeigniter - use of exit()
问题描述
我有几个网页需要登录,因此链接到这些网页的所有控制器都以
I have a few pages that require login, so all controllers that link to these pages start with
$this->checkSession();
//...rest of the code
CheckSession应该验证会话是否仍然存在,否则显示一条消息并停止执行控制器中的其余代码:
CheckSession should verify the session is still live, otherwise display a message and stop the execution of the rest of the code in the controller:
function checkSession()
{
if (!$this->session->userdata('is_logged_in'))
{
//the session has expired!
$data['main'] = 'confirmation_message';
$data['title'] = "Session expired";
$this->load->vars($data);
$this->load->view('template');
exit();
}
}
。
我期待这些指令按顺序发生,但我只得到一个空白页。
如何确保只有在所有视图加载完成后才执行exit()?
. I was expecting these instructions to happen in sequence, but I only get a blank page. How can I make sure exit() gets executed only after all views are loaded?
推荐答案
不应该使用退出,如果会话无效,您应该做的是重定向您的应用程序使用示例:
In this case you should not use exit, what you should do if the session is not valid is redirect your app using example:
redirect('/init/login/','refresh');
这篇关于PHP /代码信号器 - 使用exit()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!