1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do you hide links from search engine bots in ajax?

Discussion in 'General Scripting Chat' started by michaelr1988, May 17, 2014.

  1. michaelr1988

    michaelr1988 Regular Member

    Joined:
    Apr 25, 2011
    Messages:
    470
    Likes Received:
    307
    Location:
    UK
    How do you hide links from search engine bots in ajax? I have 3 links in my footer that I want to be visible to visitors but hidden from search engine bots. Anyone can point me in the right direction of a easy to follow guide, been struggling with this for a couple of hours now.

    Cheers.
     
  2. madworld

    madworld Newbie

    Joined:
    May 6, 2014
    Messages:
    14
    Likes Received:
    7
    Location:
    Up North
    By ajax I assume you mean JavaScript. You can get the user agent string from a visitor, but the problem is that not all crawlers/spiders use JavaScript. So the best option here is, if you can, to use something like the following PHP script:

    Code:
    <?php
    function isUserBot() {
        $bots = array(
            'googlebot',
            'bing'
            // Whatever the other bots' user agents are
        );
    
        foreach ($bots as $bot) {  
            if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), $bot)) return true;
        }
    
      return false;
    }
    ?>
    
    And then just
    Code:
    <?php if (!isUserBot()) : ?>
    <a href="#">Link 1</a> | <a href="#">Link 2</a> | ...
    <?php endif; ?>
    
     
    • Thanks Thanks x 1