Hey guys, I'd like to detect if the user is using a browser/if the user is a spider, and then use php to alter my headers accordingly. These are my header codes so for: But I want an if statement controlling what the 300 code will be and the url accordingly. adbox
In short you can check user agent of visitor. $_SERVER['HTTP_USER_AGENT']; PHP: If you have your webserver logs properly configured you can look for user agents there. Make a list of common browsers and spiders user agents. This is not a 100% way to check. One more possible method is using javascript to check if visitor is a bot or not. Spiders usually do not execute javascript, though I read somewhere that googlebot can execute some javascript.
I don;t know if I would be testing against user agents though if you're targeting search engine spiders. Too many proxies fake their user agent in an attempt to fly under the radar. If you know the ip addresses of the search engines spiders, you can give this a try: http://webtalks.blogspot.com/2007/08/want-fake-google-pagerank.html It's the same method of trying to fake a higher google pr. Hope this helps, -drmike