Jump to content

Simple Browser Redirect


illestone

Recommended Posts

You can check the value of $_SERVER['HTTP_USER_AGENT'] and do a redirect based upon that value. However, that value can be spoofed by users if they really want to. So, it is not fool-proof. You would also have to determine how you will "decide" if the browser is IE or FF.

 

Here are the contents of that variable using versions of IE7 and FF3 on my PC:

 

- Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB6.6; SLCC1; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; MS-RTC EA 2; MS-RTC LM 

- Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 GTB7.1 (.NET CLR 3.5.30729)

 

I'm sure there are some best practices, but I would guess you could check if the value contains "MSIE" or "Firefox"

You could do it in PHP or Javascript.

 

In PHP (as mjdamato said) there is the $_SERVER['HTTP_USER_AGENT'] . You could use substr to match the names of browsers (MSIE, Firefox). Then redirect using header().

 

In Javascript you could use Quirksmode's browser detection and change window.location accordingly.

Archived

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

×
×
  • Create New...

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.