Welcome Guest, Not a member yet? Register   Sign In
How to stop CI from continuing?
#13

[eluser]nwp2005[/eluser]
[quote author="Phil Sturgeon" date="1227212944"]All good replies but im not going to get into what you are trying to do as everyone else has that covered!

From a purely technical point of view, the best way to end CI and show output so far would be to make a helper file that basically just runs:

Code:
exit($this->output->get_output());

That would stop it in its tracks ^_^[/quote]

The problem with this for me is that I would like to send an HTTP status code (HTTP/1.1 401 Unauthorized) and when I use exit it ignores my header and sets it to 200 OK.

In the past I have put a call to an authentication library in the constructor of my controller like this:

Code:
$this->myauth->require_login();

the require_login() function would redirect to a login page and code execution would stop. But now I am trying to use ExtJS and I want to send an XML error but I also want to send an HTTP status code so I can use the XMLReader loadexception event. In my constructor I want to do something like this if authentication fails:

Code:
$this->output->set_header("HTTP/1.1 401 Unauthorized");
$this->output->set_header('Content-type: text/xml');
$data = '<error><error-message>Session expired</error-message></error>";
$this->load->view('template/json', $data);
exit();

But when I use exit() or die() the header status code changes to 200. If I don't include exit() or die() then code execution continues.


Messages In This Thread
How to stop CI from continuing? - by El Forum - 11-19-2008, 01:52 PM
How to stop CI from continuing? - by El Forum - 11-19-2008, 02:53 PM
How to stop CI from continuing? - by El Forum - 11-19-2008, 03:06 PM
How to stop CI from continuing? - by El Forum - 11-19-2008, 04:50 PM
How to stop CI from continuing? - by El Forum - 11-19-2008, 04:59 PM
How to stop CI from continuing? - by El Forum - 11-19-2008, 05:49 PM
How to stop CI from continuing? - by El Forum - 11-19-2008, 06:51 PM
How to stop CI from continuing? - by El Forum - 11-19-2008, 07:17 PM
How to stop CI from continuing? - by El Forum - 11-19-2008, 07:18 PM
How to stop CI from continuing? - by El Forum - 11-20-2008, 05:51 AM
How to stop CI from continuing? - by El Forum - 11-20-2008, 07:46 AM
How to stop CI from continuing? - by El Forum - 11-20-2008, 08:29 AM
How to stop CI from continuing? - by El Forum - 04-11-2009, 03:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB