PHP get_browser: how to define ie7 compared to ie6?

Is there a way to distinguish IE7 from IE6 using the PHP get_browser () function?

+2
source share
5 answers

You can do it as follows:

$browser = get_browser(); if($browser->browser == 'IE' && $browser->majorver == 6) { echo "IE6"; } elseif($browser->browser == 'IE' && $browser->majorver == 7) { echo "IE7"; } 

A quick look at the official documentation of get_browser() would answer your question. Always read the documentation before.

+27
source

I read that get_browser () is a relatively slow function, so I was looking for something faster. This code checks for MSIE 7.0, outputting "Okay!". if true. This is basically the same answer as the previous post, only more concise. Simple enough if the statement:

 <?php if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE 7.0')) echo 'Otay!'; ?> 
+4
source

Below is a complete example from here .

 $browser = get_browser(); switch ($browser->browser) { case "IE": switch ($browser->majorver) { case 7: echo '<link href="ie7.css" rel="stylesheet" type="text/css" />'; break; case 6: case 5: echo '<link href="ie5plus.css" rel="stylesheet" type="text/css" />'; break; default: echo '<link href="ieold.css" rel="stylesheet" type="text/css" />'; } break; case "Firefox": case "Mozilla": echo '<link href="gecko.css" rel="stylesheet" type="text/css" />'; break; case "Netscape": if ($browser->majorver < 5) { echo '<link href="nsold.css" rel="stylesheet" type="text/css" />'; } else { echo '<link href="gecko.css" rel="stylesheet" type="text/css" />'; } break; case "Safari": case "Konqueror": echo '<link href="gecko.css" rel="stylesheet" type="text/css" />'; break; case "Opera": echo '<link href="opera.css" rel="stylesheet" type="text/css" />'; break; default: echo '<link href="unknown.css" rel="stylesheet" type="text/css" />'; } 
+3
source

If your logic is to decide which style sheets or scripts to include, it might be worth switching to an HTML conditional comment:

 <!--[if IE 6]> According to the conditional comment this is Internet Explorer 6<br /> <![endif]--> <!--[if IE 7]> According to the conditional comment this is Internet Explorer 7<br /> <![endif]--> 

This way you can bypass any custom browser lines and the like. Additional information at QuirksMode .

+2
source

I found another, really simple solution for PHP IE6, which I was able to modify for my purposes:

 <?php // IE6 string from user_agent $ie6 = "MSIE 6.0"; // detect browser $browser = $_SERVER['HTTP_USER_AGENT']; // yank the version from the string $browser = substr("$browser", 25, 8); // if IE6 set the $alert if($browser == $ie6){ // put your code here } ?> 

The full script can be found here:

http://www.thatgrafix.com/php_detect/

0
source

Source: https://habr.com/ru/post/1397322/


All Articles