What is the purpose of using $_SERVER['HTTP_REFERER'] in PHP scripts?

$_SERVER['HTTP_REFERER'] is used in PHP scripts to track the URL of the page that referred the current page. This can be useful for various purposes such as tracking where the user came from before landing on the current page, implementing security measures to ensure requests are coming from expected sources, or customizing content based on the referring page.

if(isset($_SERVER['HTTP_REFERER'])) {
    $referer = $_SERVER['HTTP_REFERER'];
    
    // Use $referer variable for further processing
} else {
    // Handle case when HTTP_REFERER is not set
}