我想让我的网站不显示某些代码,如果他们来自某些URL。
例如,维基百科不喜欢有弹出窗口的网站链接。所以我不需要显示那个引用器的代码。
我发现了以下代码,但当代码是位置而不是文本
时,它似乎不起作用<?php $ref=getenv('HTTP_REFERER');
if (strpos($ref,"google.com")>0)
{
echo "google";
}
else
{
echo "something else";
};
?>
如果你想避免向google显示代码:
<?php if (!strstr(strtolower($_SERVER['HTTP_USER_AGENT']),"googlebot")){ ?>
//Show what you want, google will not see it
}else{
//show other code
}?>?>
为维基百科:<?php if (!strstr(strtolower($_SERVER['HTTP_REFERER']),"wikipedia")){ ?>
//Show what you want, wikipedia will not see it
}else{
//show other code
}?>
享受;)
你说的是维基百科。问题可能是google没有在其引用字符串
必须工作,尝试替代变量
<?php
$ref=$_SERVER['HTTP_REFERER'];
if (strpos($ref,"google.com")>0)
{
echo "google";
}
else
{
echo "something else";
};
?>