Page 1 of 1

HTTP_USER_AGENT

Posted: Mon Jul 05, 2004 11:13 am
by Joe
I am playing around with the HTTP_USER_AGENT function in PHP and I have came to a stop with a problem I am having. I was wondering if anyone knew how I could tell which type of browser a person was using and redirect them to the appropiate layout. :)

I know how I would go about doing it but I cannot think of how to find out if they are using internet explorer or mozilla. I thought perhaps MSIE and Mozilla?

Regards


Joe 8)

Posted: Mon Jul 05, 2004 12:14 pm
by pickle

Code: Select all

<?PHP

$user_agent = $_SERVER['HTTP_USER_AGENT'];

if(strstr($user_agent,"MSIE"))
{
     header("Location:  ie.php");
}
else if(strstr($user_agent,"Mozilla"))
{
      header("Location: gecko-based.php")
}
?>
The checks have to be in order because IE tries to identify itself as Mozilla/4.0.

This hasn't been tested, but the logic's there.

Posted: Mon Jul 05, 2004 12:33 pm
by feyd
there's [php_man]get_browser[/php_man]() too.. You can build your own version of get_browser(), if your server has it turned off.

Posted: Mon Jul 05, 2004 3:33 pm
by Joe
I thought it was MSIE and Mozilla and I was right :)

Thanks alot guys its exactly what I was looking for. Now I am going to have a good read about this get_browser() function. Sounds very interesting.

Thanks


Joe 8)