How can I detect the last visited page with php?

php

Solution

You can use sessions..

Bottom of the success.php you can assign page name to sessions

$_SESSION['page'] = $_SERVER['HTTP_REFERER'];

When click on back button you can get that value using sessions(index.php),

echo $_SESSION['page'];

On that page at the bottom, you can assign current page name to session, then it can track on next page

Problem

I am on my page index.php. From here I go with a link to myform.php. myform.php: ``` <?php echo "My last visited page is:".$_SERVER['HTTP_REFERER']; ?> <form action="success.php" method="post"> <p>Your name: <input type="text" name="name" /></p> <p><input type="submit" /></p> </form> ``` The result I see on my page is: ``` My last visited page is http://www.mypage.com/index.php ``` Now I submit my form and come to success.php. Here I click my "back" button and come again to myform.php. The result I see is now: ``` My last visited page is http://www.mypage.com/index.php ``` But what I expect here is: ``` My last visited page is http://www.mypage.com/success.php ```

Original source