# Simple php browser detection

**URL:** <https://forum.kirupa.com/t/simple-php-browser-detection/116991>\
**Category:** Uncategorized\
**Created:** [July 23, 2004, 3:53am UTC](https://forum.kirupa.com/t/simple-php-browser-detection/116991 "2004-07-23T03:53:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@Jeff\_Wheeler](https://forum.kirupa.com/u/Jeff_Wheeler)\
**Post date:** [July 23, 2004, 3:53am UTC](https://forum.kirupa.com/t/simple-php-browser-detection/116991/1 "2004-07-23T03:53:54Z")

</div>

Hello, I’m writing about how to use php browser detection to have css php files that are completely dynamic getting rid of the need to have almost any hacks. However, I need a VERY simple php script that’ll detect simply the browser, version number, and os of a client. I don’t want to use somebody’s script that I find from google because I’m going to be redistributing this to other people, and that’s why I’m looking for help. The problem is that the $\_SEVER[‘HTTP\_USER\_AGENT’] detects it as an entire string rather than just the browser type and other properties I need individually. I found got\_browser but that doesn’t work without the browscap.ini file already installed in php, which isn’t an option for most people.

Can anybody please please help me find a simple way to test the browser?

Thanks,  
Jeff ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2004, 4:22am UTC](https://forum.kirupa.com/t/simple-php-browser-detection/116991/2 "2004-07-23T04:22:59Z")

</div>

otherwise can somebody help me get the code out of [http://phpsniff.sourceforge.net/](http://phpsniff.sourceforge.net/) that I need, I couldn’t get it to work ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2004, 6:13am UTC](https://forum.kirupa.com/t/simple-php-browser-detection/116991/3 "2004-07-23T06:13:36Z")

</div>

otherwise can somebody help me get the code out of [http://phpsniff.sourceforge.net/](http://phpsniff.sourceforge.net/) that I need, I couldn’t get it to work

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2004, 6:52am UTC](https://forum.kirupa.com/t/simple-php-browser-detection/116991/4 "2004-07-23T06:52:54Z")

</div>

It won’t work as well as you might think. But here is an article that might help:

[http://www.phpbuilder.com/columns/tim20000821.php3?page=2](http://www.phpbuilder.com/columns/tim20000821.php3?page=2)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2004, 7:10am UTC](https://forum.kirupa.com/t/simple-php-browser-detection/116991/5 "2004-07-23T07:10:32Z")

</div>

I saw that, but I was just looking for browser detection, and the shortest possible method, that seems a bit excessive

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 24, 2004, 5:45am UTC](https://forum.kirupa.com/t/simple-php-browser-detection/116991/6 "2004-07-24T05:45:59Z")

</div>

anybody?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 24, 2004, 7:18am UTC](https://forum.kirupa.com/t/simple-php-browser-detection/116991/7 "2004-07-24T07:18:41Z")

</div>

```php
$browser = get_browser();
if ( $browser->browser == "IE" )
{
print ("Hellow You have IE");
}
if ( $browser->browser == "NS" )
{
print ("Hellow You have Netscape")
}
if ( $browser->browser == "FX" )
{
print ("OMG, FIREFOX, YOU THE MAN!! WAY TO GO!")
}

```

these are the shortcuts I know…

```auto
FireFox FX
Netscape NS
Mozilla MZ
Opera OP
microsoft internet explorer IE
galeon GA
phoenix PX
mozilla firebird FB
firebird FB
icab IC
lynx LX
links LI

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 24, 2004, 1:40pm UTC](https://forum.kirupa.com/t/simple-php-browser-detection/116991/8 "2004-07-24T13:40:14Z")

</div>

I found that but whenever I use getbrowser it comes up with an error about the browscap ini directive not set, so I downloaded the php\_browscap.ini file, and tried making a folder called extras in my php folder and linking to it both as extras/php\_browscap.ini and C:\php\extras\php\_browscap.ini. I have no clue on why I can’t get this function to work…

btw: nice example 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 24, 2004, 2:13pm UTC](https://forum.kirupa.com/t/simple-php-browser-detection/116991/9 "2004-07-24T14:13:48Z")

</div>

got the function to work now, but whenever I try your example it is just blank, but when I use php’s documentation’s example it works, I’ll play with it and hopefully get it 🙂
