Save Session Record
You can save the stack in a session variable. Just keep unshifting the values ββat $_SESSION["history"]
, removing elements from the end of the array when the collection grows to a certain size.
For instance:
// Need to do this if we wish to store data session_start(); // Set the history array if it doesn't exist isset( $_SESSION["history"] ) || $_SESSION["history"] = array(); // Push current URI onto history array_unshift( $_SESSION["history"], $_SERVER["REQUEST_URI"] ); // Prevent history from exceeding 5 values array_splice( $_SESSION["history"], 5 );
Download it to all PHP files
This should be added at the beginning of each file or in the global header template, if you have one. Alternatively, if you decide, you can download it globally with auto_prepend_file
:
Specifies the name of the file that is automatically parsed before the main file. The file is included as if it were called using the require function, so include_path is used. - Documentation
View the story
You can show the whole story by referring to $_SESSION["history"]
:
// Output history array var_dump( $_SESSION["history"] );
source share