# Getting Browser information

**URL:** <https://www.ruby-forum.com/t/getting-browser-information/92951>\
**Category:** Ruby\
**Created:** [April 26, 2007, 12:19am UTC](https://www.ruby-forum.com/t/getting-browser-information/92951 "2007-04-26T00:19:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [April 26, 2007, 12:19am UTC](https://www.ruby-forum.com/t/getting-browser-information/92951/1 "2007-04-26T00:19:09Z")

</div>

HI everybody,

I’m newbie to ruby. I want to get user’s browser and OS information like  
getting ip address using request.remote\_ip. Is it possible.

Regards,  
Veeraa.

---

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [April 26, 2007, 12:36am UTC](https://www.ruby-forum.com/t/getting-browser-information/92951/2 "2007-04-26T00:36:38Z")

</div>

request.env[“HTTP\_USER\_AGENT”]

Cheers,  
Ganesh G…

---

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [April 26, 2007, 2:57am UTC](https://www.ruby-forum.com/t/getting-browser-information/92951/3 "2007-04-26T02:57:12Z")

</div>

Ganesh G. wrote:

> request.env[“HTTP\_USER\_AGENT”]
> 
> Cheers,  
> Ganesh G…

Hello sir!

Thank you very much for your prompt reply .

Regards,  
Veeraa.

---

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [April 26, 2007, 3:50am UTC](https://www.ruby-forum.com/t/getting-browser-information/92951/4 "2007-04-26T03:50:01Z")

</div>

Hi,

I have one more doubt, here i want split the browser and OS information.  
But using split function is not good one. Any other way.

Regards,  
W3matter.

---

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [April 26, 2007, 12:10pm UTC](https://www.ruby-forum.com/t/getting-browser-information/92951/5 "2007-04-26T12:10:36Z")

</div>

Veera S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> HI everybody,
> 
> I’m newbie to ruby. I want to get user’s browser and OS information like  
> getting ip address using request.remote\_ip. Is it possible.
> 
> Regards,  
> Veeraa.
> 
> –

This information is part of the standard ‘agent’ information passed by  
browsers  
as an environment variable (well accessible as an environment variable).  
However, note that this information cannot be trusted (ie. its easy to  
fake and  
some browsers actually provide ways of faking it).

How you actually access this information depends on whether your using a  
ruby  
library or just reading the data from stdin from the server etc. Most  
libraries  
provide an ENV hash or object that you can query.

Tim

---

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [April 26, 2007, 1:06pm UTC](https://www.ruby-forum.com/t/getting-browser-information/92951/6 "2007-04-26T13:06:46Z")

</div>

Hello,

As you have been tool, user agent information is not 100% reliable.  
Formerly, object detection was the way to go, but this is also broken  
since Gecko and others faked the implementation of some objects (for  
instance, document.all).

I think if someone fakes his user agent he is liable for the damage  
and carry on with the consequences (i. e. not being able to view the  
website properly). What you should never do is have your security  
depend on browser detection as that is always fake-able (even if the  
evil guy has to recompile Mozilla to say it is Internet Explorer  
SuperSecureEdition).

That being said, you can use my Javascript Browser Sniffer library to  
detect the browser: [http://jsbrwsniff.sourceforge.net](http://jsbrwsniff.sourceforge.net). You can use it  
on the client side (Javascript is executed on the client) or on the  
server side (Javascript is executed on the server, this only works  
with IIS/ASP as long as I now).

–  
Pau Garcia i Quiles  
[http://www.elpauer.org](http://www.elpauer.org)  
(Due to the amount of work, I usually need 10 days to answer)

Quoting Veera S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
