if(isset($_SERVER['HTTP_REFERER'])) { $referrer = $_SERVER['HTTP_REFERER']; // Logic to store or process referrer data }
$allowed_referrers = array('mydomain.com', 'google.com'); if(isset($_SERVER['HTTP_REFERER'])) { $referrer = $_SERVER['HTTP_REFERER']; $parsed_referrer = parse_url($referrer); if(in_array($parsed_referrer['host'], $allowed_referrers)) { // Logic to accept referrer data } else { // Logic to reject referrer data } }This code not only captures the referrer data, but also checks whether it came from an allowed domain. The parse_url() function is used to extract the hostname from the referrer URL and compare it against an array of allowed domains. This is useful for preventing spam bot submissions or other unwanted referrers. Package library: The input referrer functionality is built into PHP as a standard superglobal variable, so it does not require any external package or library.