What is the difference between $HTTP_REFERER and $_SERVER['HTTP_REFERER'] in PHP?
$HTTP_REFERER is a deprecated variable in PHP that was used to retrieve the referring URL of a page. $_SERVER['HTTP_REFERER'] is the current recommended way to access the referring URL in PHP. To ensure compatibility and future-proof your code, it is recommended to use $_SERVER['HTTP_REFERER'] instead of $HTTP_REFERER.
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
echo $referer;
Related Questions
- What potential pitfalls should be considered when using the exec() function in PHP to ping an IP address and retrieve server information?
- What are the potential risks of using scripts to artificially extend session times on banking websites?
- What are the key considerations for ensuring that encrypted files are not accessible to unauthorized users in a PHP file management system?