Jump to content

if else for browser check?


Sean-Michael

Recommended Posts

Is there a simple way to use the if else function to target browsers other then FireFox and IE7?Hopefully someone can point me in the write direction to learn how to do this, what I want is to be able to display a message to viewers that are using browsers other then FireFox,IE7 ect. because I'm going to start using transparent pngs and what the viewer to know that if things dont look rite then this is due to the browser and present them with links to a few browsers that I support on my site.I guess what I mean to say is that is a viewer comes to my site with a browsers such as firefox or IE7 nothing seems to happen but if someone views with IE6 a txt file with html content will be loaded with the content I described.I've done some googling and found a few hits but I would greatly appreciate input and maybe a few pointers in the rite direction.Thanks in advance for any help!

Link to comment
Share on other sites

For this to work you have to have browscap.ini set in your php.ini

<?php$browser = get_browser(null, true);if($browser['browser'] == "IE" && $browser['version'] == "6.0"){echo "You are in Internet Explorer 6.0";}else{echo "You are not in Internet Explorer 6.0";}?>

Link to comment
Share on other sites

I guess what I mean to say is that is a viewer comes to my site with a browsers such as firefox or IE7 nothing seems to happen but if someone views with IE6 a txt file with html content will be loaded with the content I described.
There are more browsers that support what you need other then Firefox and IE7. Instead of checking for those, check for versions that don't support. Check to make sure that the browser is MSIE and that the version is less then 7. Use this page for reference:http://www.php.net/manual/en/function.get-browser.phpYou will probably want to check the browser and majorver values.
Link to comment
Share on other sites

Thank you both for your very informative replies, I think that I have the rite direction here but what I actually want is a message to display for all browsers that I haven't checked the site with personally.For example I have IE7, Firefox 2.0, that I check the site with, more as I look further into the top browsers used by Internet Surfers. Now these I know present the site as I have designed it to look but the other unknows I don't know if the layout is presented as I intend it to be, not only the png rendering but all aspects of design. For these unknows I want the message to display just under the header.looking into my browscap.ini I see no reference to IE7 but I think I can get the browsers info with...

<?phpecho $_SERVER['HTTP_USER_AGENT'] . "\n\n";$browser = get_browser(null, true);print_r($browser);?>

and use the example that "www.mihalism.com" posted for example...

<?php$browser = get_browser(null, true);if($browser['browser'] == "IE" && $browser['version'] == "7.0"){echo "Supported Browser";}elseif($browser['browser'] == "Firefox" && $browser['version'] == "2.0"){echo "Supported Browser";}else{echo "Unchecked Browser";}?>

However values for IE7 aren't showing correctly for my code to work, I believe this is due to the browscap.ini not having a value for IE7 and firefox specific 2.0?But :) when I check this with firefox "Supported Browser" is returned and when viewed with Amaya "Unchecked Browser" is returned, and IE returns "Unchecked Browser".Any further advice on the IE7 detection?Thanks again for you help!

Link to comment
Share on other sites

I doubt the version for IE7 is listed as "7.0". Most likely it is "7.0.12345" or whatever. Check the 'majorver' for '7' instead of checking 'version'.Also, I'm pretty sure that Opera will render your site correctly, or at least it will with the PNGs.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...