Home > Article > Backend Development > Why Am I Redirected to index.php After Logging In Instead of My Previous Page?
Redirecting to Previous Page After Login
When logging into a website, it's often convenient to be redirected back to the page the user was viewing before they logged in. This question explores a code issue where users are redirected to index.php instead of the intended page.
In the sample code provided, the login-check.php script determines login status and sends a redirect parameter (p) to the login.php page. However, instead of sending users to the desired page, it redirects them to index.php.
To resolve this issue, the following solution is proposed:
Pass User's Current Page as a Query String:
Handle "Location" Query String in login-check.php:
Redirect Based on Login Status and Location:
By implementing these changes, users will be successfully redirected to the page they were previously viewing after logging in, ensuring a seamless user experience.
The above is the detailed content of Why Am I Redirected to index.php After Logging In Instead of My Previous Page?. For more information, please follow other related articles on the PHP Chinese website!