Jump to content

if browser=foo, echo bar, else echo...


DaveLinger

Recommended Posts

so here's the deal. IE6 and below don't support PNG transparency, and VERY few people use IE7 so far, so I'd like to make an if statement that will echo certain code for IE users and different code for firefocks users.

like...

if([browser variable] = firefox){

}else{

}

but I dont know how to retrieve the user's browser and I don't know exactly what to check if it's equal to... like "mozilla firefox 1.5", or is it "ff1.5" or "mozilla1.5", I dont know.
Link to comment
Share on other sites

To get the user users agent (the browser) you use $_SERVER['HTTP_USER_AGENT']
You shouldn't rely on this variable too much as this can be fooled and some browsers dont send this, or disguise themeselfs.
The following is what is produced:
IE7/Win:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
Opera9/Win:
Opera/9.00 (Windows NT 5.1; U; en)
FF1.5/Win:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4
Link to comment
Share on other sites

I'm not worried about people "fooling" it, because it'd be their own fault if the site looks like crap :D

how would I have multiple choices in the if statement?

like... if($_SERVER['HTTP_USER_AGENT'] == (any of multiple agents)){

}else{}
Link to comment
Share on other sites

so I would say...

[code]

$firefocks = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4";
$IE7 = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
$Opera = "Opera/9.00 (Windows NT 5.1; U; en)";

if($_SERVER['HTTP_USER_AGENT'] == "$firefocks"|"$IE7"|"$Opera"){
echo "You have a decent web browser"
}else{
echo "omgx your browza is t3h suxx0rz.";
}
[/code]

That should work? (or a switch I guess)

@SemiApocalyptic: If it only supports full transparency I might as well be using a gif in my case =/
Link to comment
Share on other sites

Yeah... a switch would be easier. You got the OR syntax wrong anyway...

[code=php:0]
$firefocks = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4";
$IE7 = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
$Opera = "Opera/9.00 (Windows NT 5.1; U; en)";

switch ($_SERVER['HTTP_USER_AGENT']) {
  case $firefocks:
  case $IE7:
  case $Opera:
    echo "You have a decent web browser";
    break;
  default:
    echo "omgx your browza is t3h suxx0rz.";
    break;
}
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.