Answer the question
In order to leave comments, you need to log in
How to implement page history in PHP?
How to implement the display of the history of visits on the page? We have 3 files with php extension and they have links to each other. Let me explain in more detail: we are on page 1, we follow the link to page 2, and at the bottom of the page the name of the place from where we went is displayed. I know that it can be implemented using sessions, but I don’t know exactly how.
Answer the question
In order to leave comments, you need to log in
session_start();
if (isset($_SESSION['history'])) {
echo 'Вы пришли с '.end($_SESSION['history']);
}
$_SESSION['history'][] = $_SERVER['REQUEST_URI'];
You can even basically limit yourself to a referrer ($_SERVER['HTTP_REFERER'])
switch ($_SERVER['HTTP_REFERER']) {
case 'http://domain.com/page1.php':
$referer = 'PAGE #1';
break;
case 'http://domain.com/page2.php':
$referer = 'PAGE #2';
break;
case 'http://domain.com/page3.php':
$referer = 'PAGE #3';
break;
default:
$referer = '';
break;
}
// ...
if ($referer) {
echo 'Вы пришли с ' . $referer;
}
and how, it is possible that the record about which page we switched from is not replaced by a new one every time, but that the history is displayed in full. those. you come from 1, you come from 2, and so on.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question