I have a link called "buy.php" which redirects to a merchant and stores the user's IP in a database so I can track clickthroughs. A big problem I'm running into is that the IP that is recorded is often a robot/spider from the search engines so I can't compare my numbers to the merchant. Is there a way I can distinguish if the IP is a spider in my PHP script?

EDIT:

DUH, I should do this with robots.txt.

User-agent: *
Disallow: buy.php

Question: will this disallow /agdag/buy.php /ag234/buy.php or just the buy.php in the root directory?