Jump to content


Photo

Browser detection


  • Please log in to reply
4 replies to this topic

#1 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 10 July 2006 - 03:48 AM

How reliable is PHP's browser detection? I'm assuming it's set by the user agent, so is it ever wrong?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#2 willfitch

willfitch
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts
  • LocationNew Hope, PA

Posted 10 July 2006 - 03:52 AM

It's as reliable as the headers being sent to the web server. 

$_SERVER['HTTP_USER_AGENT']
Zend Certified Engineer (ZEND001989)
www.willfitch.com

#3 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 10 July 2006 - 05:16 AM

So what does that mean? php.net says $_SERVER['HTTP_REFERER'] isn't reliable because it can be modified by the user-agent. Can $_SERVER['HTTP_USER_AGENT'] be modified by the user agent?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 10 July 2006 - 05:55 AM

get_browser is an option too.

And yeah, HTTP_REFERER (and HTTP_USER_AGENT too) is very easy to spoof, but there is no spoof-proof way of getting the user agent. It works in the way that the browser actually sends the information along with the request, and you can modify what it sends quite easily.

#5 willfitch

willfitch
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts
  • LocationNew Hope, PA

Posted 10 July 2006 - 05:19 PM

Like I said, it's as reliable as the browser sending the headers.  When I wrote a C++ crawler, I sent a user agent header that corresponded with my crawler.  It is very easy to spoof, but under what circumstances are you testing this other than javascript?  Sometimes it can actually be better to detect within JavaScript, since JS would have been already downloaded.  Even better, detect with both!
Zend Certified Engineer (ZEND001989)
www.willfitch.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users