I've made CI authentication controller allowing user to log into the site, and after the login I'm redirecting him to the previously visited URL that I keep using:
$this->session->set_flashdata( 'return_url', current_url() );
Unfortunately that causes a problem. Every time when the user opens more than one tab in the browser that variable is being overwritten and after successful login the user is redirected to the same URL in all the tabs.
So my question is: Is it possible to load a custom controller inside MY_Controller? (MY_Controller
is the class that extends CI_Controller
)
I tried using (inside the constructor of MY_Controller
) but it didn't worked out:
$CI =& get_instance();
$CI->router->set_class('authentication');
$CI->router->set_method('login');
Edit: I will appreciate any other ideas of solving this 开发者_如何学Pythonproblem.
a solution would be not to save the return url in a session var, but pass it around in a get/post parameter (in case of get, properly encoded, base64 ie.). The only addition would have to be a standard return url if no (valid) return url is set
--- EDIT why was i talking about base64 when php has just the function for this; urlencode is your friend! http://nl3.php.net/urlencode
To load a custom controller inside a controller (such as MY_Controller) use php CURL to get to the authentication controller.
This may effect performance as this is an expensive process on every request.
Other options can include using a base class system (see http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY) or creating an auto-loaded library to take care of the authentication.
When you're redirecting non-logged in users to login page, keep a hidden variable "redirect_to" which will hold value from where the user has arrived. $_SERVER['HTTP_REFERRER'] can be used. Then after login, simply redirect to the value of "redirect_to". This way you don't have to set flashdata to redirect users from the url they came.
精彩评论