Php 如何允许来自多个站点的http引用程序

Php 如何允许来自多个站点的http引用程序,php,http,referrer,Php,Http,Referrer,我想知道如何允许http引用多个站点 比如说 <?php $domain='example.net'; $referrer = $_SERVER['HTTP_REFERER']; if (@preg_match("/example.net/",$referrer)) { } else { header('Location: http://www.example.net/404.php'); }; ?> 如果我打开example.net中的链接,则此代码可以工作,但我希望允许ex

我想知道如何允许http引用多个站点

比如说

<?php
$domain='example.net';
$referrer = $_SERVER['HTTP_REFERER'];
if (@preg_match("/example.net/",$referrer)) {
} else {
header('Location: http://www.example.net/404.php');
};
?>

如果我打开example.net中的链接,则此代码可以工作,但我希望允许example1.net和example2.net访问这些链接


我该怎么做?如果有人能在这方面帮助我,我们将不胜感激。

使用regex操作符或--|(管道)



如果您的目标是阻止人们访问此页面,除非作为安全方法存在于推荐人中,否则应该注意,它很容易被欺骗。请注意——在上述代码中,变量$domain没有在任何地方使用。非常感谢,非常感谢。这不是问题。我对答案进行了编辑,添加了一种更好的方法,使用您的代码作为基础。
<?php
$domains = Array(
    'example.net',      
    'example2.net'
);
$referrer = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); // Gets the domain name from referer
if (!preg_match("/" . implode('|', $domains) . "/", $referrer)) {
    header('Location: http://www.example.net/404.php');
    exit(0); //force exit script after header redirect to ensure no further code is executed.
};

// Normal code execution here...
?>