You are here:  » How to not record "clicks" on jump.php by bots

Active Forum Topics


How to not record "clicks" on jump.php by bots

Submitted by Convergence on Sat, 2013-09-21 22:51 in

Greetings,

Is there a way to create a file, example: robots.text where known bots could be added and when these bots ignore the robots.txt file and/or ignore the rel=nofollow tag that they do not trigger a click in PT?

Something similar for IPs would be nice as well, for those bots that do not identify themselves.

Clear as mud?

Submitted by support on Sun, 2013-09-22 09:31

Hi Convergence,

Yes that could be done quite easily. Since many bots actually use a standard user-agent (e.g. Mozilla/5.0) with the bot name in what's referred to as the comment section of the full user-agent string it would be necessary to test each entry in the list against the entire string rather than using an exact match.

Create your file e.g. ignore.txt containing a list of user-agents and/or IP address e.g.

BadBot1
BadBot2
127.1.2.3
192.9.8.7

(i've intentionally used private IPs in the above example!)

Then in jump.php there are couple of options. To have the script return 401 (Unauthorized) add the following code to the very top of the script (after the opening PHP tag)

  $ignores = file("ignore.txt",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
  foreach($ignores as $ignore)
  {
    if (
       (stripos($_SERVER["HTTP_USER_AGENT"],$ignore)!==FALSE)
       ||
       ($_SERVER["REMOTE_ADDR"]==$ignore)
       )
    {
      header("HTTP/1.0 401 Unauthorized");exit();
    }
  }

Alternatively, if you still want the link to work but not to trigger a click, then in place of this line:

      header("HTTP/1.0 401 Unauthorized");exit();

...use instead:

      $nolog = TRUE;break;

And then look for the following code towards the end of the script (line 12 before adding the above)

  database_queryModify($sql,$insertID);

...and REPLACE with:

  if (!isset($nolog)) database_queryModify($sql,$insertID);

Cheers,
David.
--
PriceTapestry.com