Solved

Redirect to the page requested before login

Posted on 2009-05-03
2
497 Views
Last Modified: 2013-12-13
Hi experts,
Please help me solve this problem:

Suppose a user tries to access 'http://localhost/dir A/restricted.php' page. Since the user is not logged in, he is redirected to 'login.php' page.
Once the user logs in successfully, he is redirected to the page he previously requsted that is : 'http://localhost/dir A/restricted.php.'

Please help me know, how can i implement this redirection to the previously requested page after the user logs in?

Thanks
0
Comment
Question by:sandhya01
2 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 125 total points
Comment Utility
When you check access and decide you need to redirect to login.php, either set a session variable or include the url of the page in the url to login.php. Then in login.php, check if this session/url variable exists, if so, redirect to that page after a successfull login. If you use the url variable emthod, you must also put it as a hidden variable on the login form, and fetch it after login so that you know where to redirect. Remember to use urlencode() when you put an url within the url.
0
 
LVL 10

Assisted Solution

by:stormist
stormist earned 125 total points
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now