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();
}
?>