Why is clicking on a link necessary for the $_SERVER['HTTP_REFERER'] variable to contain data?
When a user clicks on a link to navigate from one page to another, the HTTP_REFERER variable in the $_SERVER superglobal is populated with the URL of the previous page. If a user directly types in a URL or accesses a page through a bookmark, the HTTP_REFERER variable will be empty. To ensure that the HTTP_REFERER variable contains data, users must navigate through links on the website.
// Check if the HTTP_REFERER variable is set and not empty
if(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])){
// Use the HTTP_REFERER variable for further processing
$previousPage = $_SERVER['HTTP_REFERER'];
echo "Previous Page: " . $previousPage;
} else {
echo "HTTP_REFERER variable is empty.";
}