0

I am working on a site that allows system user login. And I face some scenario below:

If let say User A clicked on an email link (https://www.example.com/user/1), User A will be redirected to the login page if haven't login or User A will be redirected to the email clicked URL if User A already logged in. The question here is that how to redirect User A to the email clicked URL right after login successful instead of https://www.example.com/home by default.

Correct me if I'm wrong.

1
  • 1
    Before redirecting the user to login, store the current URL into the session. Read it back from & redirect there after successful login. Commented Jul 20, 2016 at 7:53

1 Answer 1

1

There are 2 approaches to achieve it:

1. Sending the data in GET request: I see many (big) websites are doing that, just send a GET info to the www.example.com/home, let's say will look like that: www.example.com/home?redirect=email, you can send how many variables you want, you can also use hash to make it more secure and less readable for the user, you can choose this approach if you don't want to create a SESSION for the user for this tiny issue.

2. Saving the request in SESSION: if the user is not logged in, create a SESSION with the desired location to redirect, then get that SESSION variable in the /home through $_SESSION or through other methods (if you use a framework such as Laravel).

I suggest go with approach 1, it is very common. The reason I think it is better than approach 2 is because that this task is not what Sessions are for.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.