How can the Referer be used to determine the source of a page request in PHP?
The Referer header can be used in PHP to determine the source of a page request by checking the value of $_SERVER['HTTP_REFERER']. This can be useful for tracking where visitors are coming from or implementing referral-based functionality on a website.
if(isset($_SERVER['HTTP_REFERER'])) {
$referer = $_SERVER['HTTP_REFERER'];
// Use $referer to determine the source of the page request
echo "The page was accessed from: " . $referer;
} else {
echo "No referer information available.";
}
Keywords
Related Questions
- What is the correct way to execute an SQL INSERT statement in PHP after defining it in a variable?
- How can the PHP code be optimized to improve the functionality and user experience of the popups with iframes?
- How can PHP be used to read HTTP headers and handle 301 redirects that result in a 200 status code?