redirect after login |
[eluser]UnknownPlayer[/eluser]
Hi, can someone give me code how can i redirect after login on refferer page ? I had php code, but it doesn't work always, so if anyone have good example ?
[eluser]Kraig[/eluser]
[quote author="Ayeyermaw" date="1325927347"]I use tend to use Code: $this->router->fetch_class() I just woke up so wouldn't dare write example code for you incase it was wrong but hope that helps[/quote] Are you meaning that with this you, after login the user will be redirected to their current page? I am having problems using $link = current_url(); because it is redirecting the user back to a function in the login class.
[eluser]Ayeyermaw[/eluser]
[quote author="Kraig" date="1331182666"] Are you meaning that with this you, after login the user will be redirected to their current page? I am having problems using $link = current_url(); because it is redirecting the user back to a function in the login class.[/quote] Without knowing how you are using current_url() it's difficult to help you here so i'll give you and example using it. In MY_Controller: Code: public function __construct() and in your login controller (Note: MyLoginController should not extend MY_Controller) you'd have something like this: Code: // On successful login The above code is untested but it should give you an idea of what to do. Hope that helps
[eluser]Kraig[/eluser]
I have a home controller that has a validate_credentials() function. So when the user attempts to login this is the function that gets called no matter what page they are on. The problem I am having is that when I am on a different page and attempt to login, it redirects me back to the validate_credentials page when using current_url(). It still logs me in, but I want it to redirect back to the previous page. By the way I am using a jQuery login...so I'm on the current page until it redirects me.
[eluser]Ayeyermaw[/eluser]
You need to go through it step by step and figure out where current_url is being set to the validate_credentials link. I can't help you here as I can't see your code. My guess is that your jquery login might be using ajax to check login credentials. If that's the case then current_url will be whatever url your ajax call is using. Not where your browser is pointing
[eluser]Kraig[/eluser]
Ok, my login form is this: I am using an Ajax login Code: <?php echo form_open('home/validate_credentials'); ?> My Home Controller function is this: Code: public function validate_credentials()
[eluser]Ayeyermaw[/eluser]
current_url() will always be the value of the url you have requested so that's why after you post you are getting that value. You have to save the value of current_url() to a session variable at the page where you want to return to. You can do that using my example above or you can set it in the construct of every individual controller just before you redirect to the login page. From that point on you'll have the redirect page in session memory and you can call on it in your validate_credentials function. instead of Code: redirect('home/home'); Code: redirect($this->session->userdata('return_url'))
[eluser]Kraig[/eluser]
So in order for this to work I would need to add Code: if (!logged_in) to every Controller construct?? Doesn't that seem a little redundant, especially if you are going to use it for every page?
[eluser]Ayeyermaw[/eluser]
Nope... scroll up and read the part about MY_Controller
[eluser]Kraig[/eluser]
Isn't MY_Controller just the name of the controller that you are in? So if I have 3 controllers leading to 3 different pages I would have to include Code: public function __construct() into every controller file. I notice that you said you use Code: $this->router->fetch_class() |
Welcome Guest, Not a member yet? Register Sign In |