doupo2241 2017-04-24 01:23
浏览 41
已采纳

隐藏真实背后的机制是什么?

According to this "Cloaking refers to the practice of presenting different content or URLs to human users and search engines" The same link gives example as:

Serving a page of HTML text to search engines, while showing a page of images or Flash to users

Question: If I had correctly interpreted, there must be a mechanism for identification of the entity whether it is search engine or browser(user) at the web server.What do we call such mechanism? Or is it just a php or JavaScript code that redirects? How does a web-server actually know that entity'X' search engine and entity'Y' is web browser?

  • 写回答

1条回答 默认 最新

  • doumianfeng5065 2017-04-24 01:33
    关注

    The user agent is a good way to identify the client.

    This is the user agent string passed to the server on a request from a browser:

    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"

    From Google:

    Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

    From Bing:

    Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)

    To use them with PHP, you may do something like this:

    if (strpos($_SERVER['HTTP_USER_AGENT'],'bot') !== false) {
        // This is probably a bot
    }
    

    If you want to be a little more precise, you might want to also check for a link, like so:

    $userAgent = $_SERVER['HTTP_USER_AGENT'];
    if (strpos($userAgent,'bot') !== false && strpos($userAgent,'http') !== false) {
        // It is probably a bot
    }
    

    This question and answers show how to use Apache to deliver different content based on user agent: Rewrite rule for user agent with mod_rewrite

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题