PHP gets the URL of the previous page after redirecting

I want to have a navigation bar that tells the user where they came from. Example: Homepage → Message

But if they are in their post manager and click on the message, I want him to say Message Manager → Message

I read that it’s $_SERVER['HTTP_REFERER']not good enough to get the full URL, so that it is not useful, since I want the navigation bar to be clicked for everyone

Any help is much appreciated!

+4
source share
4 answers

I believe you want breadcrumbs .

. $_SERVER ['HTTP_REFERER'], , , . URI .

, URI: http://www.example.com/post_manager/post

explode("/", $_SERVER["REQUEST_URI"]), .

, . google alot , breadcrumbs.

( , , ): . :

:

<?php
    session_start(); 
    $_SESSION['previous_location'] = 'homepage';
?>

:

<?php
    $previous_location = $_SESSION['previous_location'];
?>

session.save_path PHP, .

+8

, javascript document.referrer. .

if (!isset($_SESSION['referrer'])) {
    $_SESSION['referrer'] = $current_uri;
} else {
    $previous_uri = $_SESSION['referrer'];
    $_SESSION['referrer'] = $current_uri;
}
+2

IMO , , "" ( ), , , 2 , . .

+1
<?php
    session_start(); 
    $_SESSION['user_interactions'][] = $_SERVER['HTTP_REFERER'];

    // get previous
    $previous_page = end($_SESSION['user_interactions']);

    // list all user interactions
    foreach($_SESSION['user_interactions'] as $key => $value){
        echo $value;
        if(count($_SESSION['user_interactions'])-1 != $key) echo ">";

    }
?>
0

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


All Articles