Page 1 of 1

Script won't identify browser - correctly - anyone know why?

Posted: Thu Nov 24, 2011 11:14 am
by simonmlewis
http://chrisschuld.com/projects/browser ... -from-php/

This page shows ways to get the browser type.

Code: Select all

$browser = $_SERVER['HTTP_USER_AGENT'];
If I do this in Firefox, it shows up as
[text]Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0[/text]

But if I do it in Internet Explorer 9, it shows up as:
[text]Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)[/text]

I need to be able to find out what the browser is, to show one of two different images (that differ because of layout differences.).

Re: Script won't identify browser - correctly - anyone know

Posted: Thu Nov 24, 2011 11:24 am
by twinedev
Well, first what is the deciding factor that will trip a different layout? If you are needing it only for firefox:

Code: Select all

if (strpos($_SERVER['HTTP_USER_AGENT'],'Firefox')!==FALSE) {
    // They are using firefox
} else {
    // They are using something else.
}
To change it to check for for IE, just use MSIE (uppercase) in the first line instead of Firefox

-Greg

Re: Script won't identify browser - correctly - anyone know

Posted: Thu Nov 24, 2011 12:21 pm
by simonmlewis
Perfect. Duno why mine didn't work, but I think it's that "compatible" bit of the code, and cliearly yours looks in the extract code for a particular term.

It's because IE plays with widths of divs and images differently from Firefox. And I have to get some boxes to line up with an image.

Ta!!

Re: Script won't identify browser - correctly - anyone know

Posted: Fri Nov 25, 2011 2:48 am
by twinedev
what about using conditional CSS includes?

Code: Select all

<link href="/main.css" rel="stylesheet" type="text/css">
<!--[if IE]>
    <link href="/ie-hack.css" rel="stylesheet" type="text/css">
<![endif]-->
(granted, I'm a programmer, just know that the development company I worked for used those all over to fix the way IE crapped on CSS behavior LOL)

Re: Script won't identify browser - correctly - anyone know

Posted: Fri Nov 25, 2011 2:52 am
by simonmlewis
Already on my mind now..... :) Thx.