检查两个php页面之间的最后一次访问

Is there some sort of PHP code that allows me figure out which of the two pages was last visited.

Here is why i need it.

I have 3 pages called:

user-management.php, manage-membership.php and manage-user.php

There are two ways of getting to manage-user.php. One is to click on the name of the user in user-management.php and the other is to click on the membership account holder in membership-management. Both user-management and membership-management are completely different pages so please don't tell me to merge them to make it easier, because it won't get easier.

What i want to do is track where i'm coming from.

For example, if i'm going to manage-user.php from user-management.php, when all the editing is done, i want it to redirect back to user-management.php, and the same for membership-management.

How do i check to see which of the two pages I came from and redirect back to those pages accordingly?

Have each of your scripts record their name in the $_SESSION, so you're keeping track of where you came from:

user-management.php:

$_SESSION['came_from'] = 'user-management.php';

and then in your manage-user.php script:

<a href="<?php echo $_SESSION['came_from'] ?>">Back</a>

This is more reliable than using the HTTP referer, because not everyone sends refers, or sends the ACTUAL referer.

you could use $_SERVER['HTTP_REFERER']; But this is not so safe, better store the page in a session and check it then.

session_start();
...
$_SESSION['log'][] = $_SERVER['PHP_SELF'];
...
if ($_SESSION['log'][count($_SESSION['log'])-1] == "xxx") {
  do code...
}

Tried this? -> $_SERVER["HTTP_REFERER"]

You can read more from this: http://www.electrictoolbox.com/php-http-referer-variable/

You could use $_SERVER['HTTP_REFERER']; but the user can also set their browser to not send the referer header. You could also do something like this:

At beginning of page:

session_start();
$lastVisited = $_SESSION['last_visited'];

At end:

$_SESSION['last_visited'] = $thisPagename;