Checking last visit between two php pages

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

That is why I need it.

I have 3 pages:

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

There are two ways to access manage-user.php. One is to click the username in user-management.php, and the other is to click on the membership management account holder. Both user management and membership management are completely different pages, so please do not tell me to combine them in order to simplify them, because it will become easier.

What I want to do is keep track of where I come from.

For example, if I am 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 can I check which of the two pages I came from and redirect back to these pages?

+1
source share
4 answers

Let each of your scripts write its name in $ _SESSION, so you keep track of where you came from:

by management.php user:

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

and then in the manage-user.php script file:

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

This is more reliable than using HTTP abstracting because not everyone sends a link or sends an ACTUAL referent.

+2
source

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

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

Have you tried this? → $ _ SERVER ["HTTP_REFERER"]

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

0
source

You can use $_SERVER['HTTP_REFERER']; , but the user can also configure the browser to send the abstract header. You can also do something like this:

At the beginning of the page:

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

In the end:

 $_SESSION['last_visited'] = $thisPagename; 
0
source

Source: https://habr.com/ru/post/969991/


All Articles