D
D
Dead_Cat_Bounce2014-05-27 13:32:33
PHP
Dead_Cat_Bounce, 2014-05-27 13:32:33

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

3 answer(s)
B
BoneFletcher, 2014-05-27
@Dead_Cat_Bounce

session_start();
if (isset($_SESSION['history'])) {
    echo 'Вы пришли с '.end($_SESSION['history']);
}
$_SESSION['history'][] = $_SERVER['REQUEST_URI'];

I
Ilya Lesnykh, 2014-05-27
@Aliance

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;
}

D
Dead_Cat_Bounce, 2014-05-27
@Dead_Cat_Bounce

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 question

Ask a Question

731 491 924 answers to any question