Detect if visitor is using browser and modify header info

Discussion in 'PHP' started by adbox, Nov 16, 2009.

  1. #1
    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
     
    adbox, Nov 16, 2009 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    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.
     
    AsHinE, Nov 16, 2009 IP
  3. theapparatus

    theapparatus Peon

    Messages:
    2,925
    Likes Received:
    119
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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
     
    theapparatus, Nov 16, 2009 IP