HTTP_USER_AGENT

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

HTTP_USER_AGENT

Post 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)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post 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)
Post Reply