note 114940 deleted from function.register-shutdown-function by crell
| From: | crell@php.net | Date: | Wed, 30 Mar 2022 22:05:15 +0000 |
| Subject: | note 114940 deleted from function.register-shutdown-function by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217808@lists.php.net to get a copy of this message | ||
Note Submitter: m dot agkopian at gmail dot com
----
Use this small snippet inside your bootstrap in order to always have a way to know reliably what was
the last page of your site that the user have visited, without having to use
$_SERVER['HTTP_REFERER'].
<?php
session_start();
// Get current page
$current_page = htmlspecialchars($_SERVER['SCRIPT_NAME'], ENT_QUOTES, 'UTF-8');
$current_page .= $_SERVER['QUERY_STRING'] ?
'?'.htmlspecialchars($_SERVER['QUERY_STRING'], ENT_QUOTES, 'UTF-8') :
'';
// Set previous page at the end
register_shutdown_function(function ($current_page) {
$_SESSION['previous_page'] = $current_page;
}, $current_page);
?>