I have a page named Login.php
. I need the URL of the page before the last page.
When the user login form will submit to check_login.php
which checks their username and password. Then I will redirect the user to index.php
.
The issue is I want the user to be redirected to the second to last page they visited.
EXAMPLE:
First URL: www.example.com/posts/1
Second URL: www.example.com/login.php
Third URL: wwww.example.com/check_login.php
So, if username and password are correct => header('location: www.example.com/posts/1');
There is a solution to get the previous URL:
// login.php
$_SESSION['url'] = $_SERVER['HTTP_REFERER'];
// check_login.php
header('location: '.$_SESSION['url']);
But I need to get the second to last URL, not the last URL. How can I do this in PHP?