How can PHP be utilized to block specific referrers and redirect to an ErrorDocument in a PHP website?
To block specific referrers and redirect to an ErrorDocument in a PHP website, you can check the HTTP_REFERER header in PHP and redirect to the ErrorDocument if the referrer matches the blocked referrers.
<?php
$blocked_referrers = array("blockedreferrer.com", "anotherblockedreferrer.com");
if (in_array($_SERVER['HTTP_REFERER'], $blocked_referrers)) {
header("Location: /error.html");
exit();
}
?>
Keywords
Related Questions
- How can manual session management be implemented in PHP to ensure sessions are properly cleaned up?
- How can the code snippet be improved to ensure that SESSION content is properly destroyed and not retained?
- How can beginners improve their understanding and usage of the "->" operator in PHP programming?