DaveLinger Posted July 24, 2006 Share Posted July 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/15505-if-browserfoo-echo-bar-else-echo/ Share on other sites More sharing options...
wildteen88 Posted July 24, 2006 Share Posted July 24, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/15505-if-browserfoo-echo-bar-else-echo/#findComment-62942 Share on other sites More sharing options...
DaveLinger Posted July 24, 2006 Author Share Posted July 24, 2006 I'm not worried about people "fooling" it, because it'd be their own fault if the site looks like crap :Dhow would I have multiple choices in the if statement?like... if($_SERVER['HTTP_USER_AGENT'] == (any of multiple agents)){}else{} Quote Link to comment https://forums.phpfreaks.com/topic/15505-if-browserfoo-echo-bar-else-echo/#findComment-62947 Share on other sites More sharing options...
trq Posted July 24, 2006 Share Posted July 24, 2006 Use || Quote Link to comment https://forums.phpfreaks.com/topic/15505-if-browserfoo-echo-bar-else-echo/#findComment-62962 Share on other sites More sharing options...
wildteen88 Posted July 24, 2006 Share Posted July 24, 2006 This article [url=http://www.stylegala.com/articles/no_more_css_hacks.htm]here[/url], shows how to use browser specific CSS with PHP. It shows how to correctly detect the user agent etc. Quote Link to comment https://forums.phpfreaks.com/topic/15505-if-browserfoo-echo-bar-else-echo/#findComment-62966 Share on other sites More sharing options...
Joe Haley Posted July 24, 2006 Share Posted July 24, 2006 [quote author=thorpe link=topic=101694.msg402674#msg402674 date=1153758938]Use ||[/quote]I would use a switch. (easyer to read and expand) Quote Link to comment https://forums.phpfreaks.com/topic/15505-if-browserfoo-echo-bar-else-echo/#findComment-62968 Share on other sites More sharing options...
zq29 Posted July 24, 2006 Share Posted July 24, 2006 Just as a side note, IE6 does support full transparancy within png images, it doesn't support gradual transparency/opacity. Quote Link to comment https://forums.phpfreaks.com/topic/15505-if-browserfoo-echo-bar-else-echo/#findComment-62970 Share on other sites More sharing options...
DaveLinger Posted July 24, 2006 Author Share Posted July 24, 2006 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 =/ Quote Link to comment https://forums.phpfreaks.com/topic/15505-if-browserfoo-echo-bar-else-echo/#findComment-62972 Share on other sites More sharing options...
trq Posted July 24, 2006 Share Posted July 24, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/15505-if-browserfoo-echo-bar-else-echo/#findComment-62985 Share on other sites More sharing options...
DaveLinger Posted July 24, 2006 Author Share Posted July 24, 2006 rofl firefocks makes me laffles.Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/15505-if-browserfoo-echo-bar-else-echo/#findComment-62988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.