1

私はphpについてほとんど何も知らないので、これはおそらく誰かを笑わせるでしょう。

ホストヘッダーをチェックし、一致が見つかった場合はリダイレクトするこのコードが index.php にあります。

if (!preg_match("/site1.net.nz/",$host)) {
    header('Location: http://www.siteblah.net.nz/temp_internet_block.cfm');
}

ただし、潜在的に複数のサイトをチェックする必要があります。次のように。

if (!preg_match("/site1.net.nz/"|"/site2.net.nz",$host)) {
    header('Location: http://www.siteblah.net.nz/temp_internet_block.cfm');
}

これは実際に私が知っているすべての正しい構文かもしれません:-)

4

4 に答える 4

1

試す、

$hosts="/(site1\.com)|(site2\.com)/";
if (!preg_match($hosts,$host)) {
  // do something.
}
于 2012-07-30T08:05:00.460 に答える
1
if (!preg_match("/(site1\.net\.nz|site2\.net\.nz|some\.other\.domain)/",$host)) {
    header('Location: http://www.siteblah.net.nz/temp_internet_block.cfm');
}
于 2012-07-30T08:04:12.383 に答える
0
// [12] to match 1 or 2
// also need to escape . for match real . otherwise . will match any char
if (!preg_match("/site[12]\.net\.nz/",$host)) {
    header('Location: http://www.siteblah.net.nz/temp_internet_block.cfm');
}

または

if (!preg_match("/site1\.net\.nz|site2\.net\.nz/",$host)) {
    header('Location: http://www.siteblah.net.nz/temp_internet_block.cfm');
}
于 2012-07-30T08:01:40.780 に答える