[eluser]CI Nick[/eluser]
Hello all.
Here's the scenario:
User tries to access a secure page on my site. Sentry class checks if they are logged in and redirects them to the login page. I then store the url they were trying to access in the session (using standard CI session cookie). If they login successfully, they are sent to the page they were originally trying to access by retrieving the url from the cookie. I've written a library so that every redirect first checks if there is a url saved in the cookie before the redirect happens:
Code:
class Redirect {
var $ci;
function Redirect()
{
//Get CI instance
$this->ci =& get_instance();
}
function send_to($url_default)
{
if($url_to = $this->ci->session->userdata('url_to'))
{
$this->ci->session->unset_userdata('url_to');
return $url_to;
}
else
{
return $url_default;
}
}
}
And all my redirect calls look like this:
Code:
redirect($this->redirect->send_to('my_page'));
So if there is a saved url in the cookie, you get redirected to that page, otherwise, you get redirected to the page you send to the "send_to" method in my Redirect class.
The problem is that the unset_userdata call (when a stored url has been found) is not un-setting that session variable. If I put an exit call after the unset it works, so it's as if the code is not getting a chance to run before the return happens.
If anyone followed all that, would you know why this is hapening? Is it bad code from me or is there a bug with CI?
Thanks in advance,
Nick.