php代码排除谷歌

发布于 2024-12-17 18:41:32 字数 342 浏览 3 评论 0原文

我有一个分类广告网站。在这个网站上,我将用户访问的每个产品页面存储在数据库中以用于历史记录,以便他可以查看他访问的最后产品。

问题是,当 googlebot 和其他人进入我的网站时,数据库会填满数千个条目,因为它会损害 Google 访问的数千个产品页面。

我尝试了 $_SERVER['HTTP_USER_AGENT'] 的各种功能,试图查明当前用户是否是 googlebot,如果是,则不会影响数据库中的页面视图,以免收到垃圾邮件结果没有用,但它们似乎都不起作用,因为我得到了 Google ip 并在我的数据库中识别它们。

你们中有人知道 php 中确保 google 不被访问的好方法吗?

i have a classifieds website. On this website i store in the db, each product page that a user visits for history purposes, so he can view the last products he visited.

The problem is that when googlebot and others enter my site, the db fills up with thousands of entrys because it sores the thousand product pages Google visit.

I tried various functions with $_SERVER['HTTP_USER_AGENT'] to try to find out is the current user is googlebot or not and if it is, not sore the page views in the db so that it's not spammed with unusefull results but none of them seem to work, as i get the Google ip's and recognize them in my db.

Do any of you know a good way in php to ensure google stays out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

征﹌骨岁月お 2024-12-24 18:41:32

您可以使用以下片段,它应该检测 GoogleBot 并且不存储到数据库。

if (!strpos($_SERVER['HTTP_USER_AGENT'],"Googlebot")) {
     // log to database
}

You can use the following snippit which should detect the GoogleBot and not store to the database.

if (!strpos($_SERVER['HTTP_USER_AGENT'],"Googlebot")) {
     // log to database
}
撩发小公举 2024-12-24 18:41:32

为什么你只想将谷歌拒之门外?其他搜索引擎也可能会索引您的网站。 bing、yahoo、altavista 等怎么样?

您可以使用 robots.txt 禁止任何抓取工具为您的网站建立索引。

在你的根目录中创建一个 robots.txt 并在其中添加以下内容:

User-agent: *
Disallow: /

如果你想在某些页面上允许爬虫,你可以设置元数据 并不是

<meta name="robots" content="noindex, nofollow" />

所有的机器人都是“好”的并且尊重这些标签。

Why in the world would you want to only keep google out? Other search-engines may index your site aswell. What about bing, yahoo, altavista and others?

You can make use of a robots.txt to disallow any crawler to index your site.

Make a robots.txt in your root and put the following in it:

User-agent: *
Disallow: /

If you want to allow crawlers on some page tho, you can set the meta instead

<meta name="robots" content="noindex, nofollow" />

Not all bots are "nice" and respect these tags tho.

自控 2024-12-24 18:41:32

您是否考虑过网上冲浪的所有其他机器人、蜘蛛和自动脚本?他们还将填充您的数据库。找出所有这些 UserAgents、IP 和其他特征是地狱般的事情。也许最好将历史记录限制为 25 个条目。

所以我的答案是:限制历史数据库的条目将历史记录存储在访问者客户端的 cookie 中。

Did you think about all the other robots, spiders and automatic scripts surfing the web? They will also fill up your database. And it is hell to find out about all those UserAgents, IPs and other characteristics. Maybe it's better you just limit the history to lets say 25 entries.

So my answer is: limit the entries of your history db or store the history in a cookie in the visitors client.

你在我安 2024-12-24 18:41:32
<?php echo $_SERVER['REMOTE_ADDR'];?> 

会给您客户的地址。然后,您设置一个会话变量,该变量将根据您检查 IP 的逻辑来存储或丢弃页面。

@Jan 的答案是更好的方法。虽然那样会切断所有机器人的联系。

<?php echo $_SERVER['REMOTE_ADDR'];?> 

will give you the address of the client. Then you set a session variable that will store or discard the pages based on your logic checking the ip.

@Jan's answer is better way. Although that will cut off all robots.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文