What are the potential pitfalls of using $_SERVER['HTTP_REFERER'] to track user navigation?

Using $_SERVER['HTTP_REFERER'] to track user navigation can be unreliable as it relies on the browser to send the referrer information, which can be easily manipulated or blocked by the user. To overcome this limitation, consider using session variables or cookies to track user navigation within your application.

// Start or resume a session
session_start();

// Track user navigation using session variables
if(isset($_SESSION['navigation'])){
    $_SESSION['navigation'][] = $_SERVER['REQUEST_URI'];
} else {
    $_SESSION['navigation'] = array($_SERVER['REQUEST_URI']);
}