接受来自uniqe推荐人的访客

时间:2017-01-31 10:13:17

标签: php referrer

这是合约 我想接受仅来自Google搜索推荐者的访问者访问我的网站 因此,如果他们在网址栏中输入“domain.com”,则必须出现Google搜索“domain.com”。 有人可以告诉我这个或其他东西的Php代码吗? 感谢

1 个答案:

答案 0 :(得分:0)

如果他们不是来自谷歌搜索页面,您可以随时查看$_SERVER['HTTP_REFERER']并将其重定向到https://www.google.co.in/search?q=yourwebsite.com。但这并不高效,因为这可能会触发Google垃圾邮件检测。我不完全确定垃圾邮件检测,但我可以建议一种在我看来更好的替代方案。

//say your website URL is example.com. Someone landed in example.com
$url = $_SERVER['HTTP_REFERER'];
$host = parse_url ($url, PHP_URL_HOST);
if (strstr ($host, 'www.google.')) {
//someone can still spoof this. If you need more restriction, you need to check all google regional domains explicitly.
//https://en.wikipedia.org/wiki/List_of_Google_domains
    header('Location: example.com/welcome');
} else{
    header('Location: example.com/redirect');
}

现在在redirect页面,你需要做的伎俩。您自动填写表格并使用javascript自动提交。

<form id="myForm" action="https://www.google.com/search" method="get">
<input type="hidden" name="q" lang="en" value="example.com">
</form>
<script type="text/javascript">
  document.getElementById('myForm').submit();
</script>

现在,用户将被带到谷歌搜索结果页面,您的网站将成为第一个结果。