redirecting page after login in codeigniter - codeigniter

I am quite newbie to codeigniter, I have login system to start with on site, and have 2 scenario:
If user is already logged in, and if clicks on url from other site(different domain), then it will redirect to given link.
If user is not logged in and click on link from other domain then he will first redirect to login page and then he will redirect again to clicked link.
now my first case works but not second, I tried setting a url in session like,
$array['login_redirect'] = current_url();
$this->session->set_userdata($array);
which is giving me correct url
but after login, session data shows login page url as value for login_redirect.

You need to add condition to set current url.
for Example:
$current_url = current_url();
$login_url = 'www.test.com/login'; // Login url of current website
if($current_url != $login_url){
$array['login_redirect'] = $current_url;
$this->session->set_userdata($array);
}

You can save current url in session when user is not logged in and don't do it when user is on login page - then you can read link from session and it will be link to last visited page.
Another solution is to save url to page in cookie when user clicks on link and then you can read it in PHP and redirect user to correct page.
Third solutiuon is to send this link via POST or GET when user is redirected to login page.

Related

Liferay redirect to user's entered page post login

I have created a custom landing page hook in Liferay6.2.
Suppose user enters abc.com/xyz. Then after login he should not be redirected to my custom landing page. Instead he should be redirected to xyz post login.
My landing page should be selected only when he enters abc.com
How to implement this.
This can be fetched using below code in your PostLogin Hook
LastPath lastPath = (LastPath) session.getAttribute(WebKeys.LAST_PATH);

logout session revisiting pages codeigniter

The problem is after i logout, then press back button or go to user_control/login, then refresh, i wasn't redirected to the log in page but rather at the home page.
I unset and destroyed the session already.
One solution i found from the web is no cache. It works but it prompts for the resubmission of form and when i refresh i wasn't redirected to the login page but rather at the home page.
> controller: user_control
> function: login
> algorithm:
> 1. form validation set rules
> 2. get posts of username and password
> 3. check if the username is in the database and entered password is equal to the password in the database, if true go to 4. else go to signin page.
> 4. set session
> 5. load view home.php
I suspect, everytime i press the back button, the post request is still there, and when i refresh, it calls the user_control/login with the posts credentials of the form.
You need to restrict your home page or any other pages to only logged in users. Redirect others to the login page. Have a look at Ion Auth documents for an example of how this can be done.

Get the target url from the login page

Is there a way to get the "cached" target url from the login jsp page if that login page is displayed because the user typed the url of a page that requires authentication?
I need to know if the login page is displayed because the user typed the url of the login page directly or if the login page is displayed because the previous page requires authentication.
Thanks.
Ok, here is how to do with Spring 3.x:
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response)
which is null if there is no redirect, if not null, to get the url:
savedRequest.getRedirectUrl()

Incorrect Login Goes to 404 instead of LogIn Page

I am trying to set up a login portion for my site - and the login is working fine. However, if the login is incorrect, it goes to a 404 page instead of a login page. How can I fix this?
Most joomla login modules have parameters for redirecting users to a menu or a url after successful or unsuccessful login. I guess yours is redirecting users to an upublished menu or item or a broken link.
If you are using Joomla's native Login module or something like mod_k2_user, There should be a parameter called Login Redirection Page which you can point it to a published menu item.
Go to your administrator area, module manager and find your login module an take a look at it's parameters.

Manage Login Redirection in Pyrocms

I need to manage login in such a way that it should redirect the control after successful login to the page which call login method in pyrocms.
By default it return control to Home Page. for example i want to go gallery page but it require user to be logged in so it will redirect control to the login page and now i want to redirect the control back to the gallery page once the user successful logged in.
Finally, i have come with the exact solution which is working correctly for me.
Whenever user try to view the gallery page(restricted page) which require user login, we have to only assign the URL where we want to redirect after successful login in $redirect_to in the controller method:
$this->session->set_userdata('redirect_to',$redirect_to);
Then it will automatically redirect the control to the desired page. Because in the users controller the login function is developed in such a way that:
$redirect_to = $this->input->post('redirect_to') ? $this->input->post('redirect_to') : $this->session->userdata('redirect_to');
Hopefully this will help you sometime

Resources