Jump to content

Archived

This topic is now archived and is closed to further replies.

johnnyk

Browser detection

Recommended Posts

How reliable is PHP's browser detection? I'm assuming it's set by the user agent, so is it ever wrong?

Share this post


Link to post
Share on other sites
It's as reliable as the headers being sent to the web server. 

$_SERVER['HTTP_USER_AGENT']

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[url=http://php.net/get_browser]get_browser[/url] is an option too.

And yeah, HTTP_REFERER (and HTTP_USER_AGENT too) is [i]very[/i] 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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.