问题
For detecting Internet Explorer I use his line.
<?php if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) { };?>
How do I detect iOS 5.
回答1:
The HTTP_USER_AGENT will return the following:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
If you are trying to detect iOS 5, do the following:
<?php if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone OS 5_0') !== false) { };?>
回答2:
I had a similar problem but needed to get the version number in iPhone and iPad using $_SERVER['HTTP_USER_AGENT']. I suppose it is not completely reliable, but it worked for me:
<?php
$version = preg_replace("/(.*) OS ([0-9]*)_(.*)/","$2", $_SERVER['HTTP_USER_AGENT']);
// for example you use it this way
if ($version > 5){
// do something
}
?>
回答3:
If this is possible, get_browser() will be the way to do it.
However, since a User-Agent string is easily spoofable, and the list of browsers/OSes is a constantly moving target, this will never be 100% reliable. In order for this to work at all, you must keep the php_browscap.ini
file up to date (see note on the linked manual page).
回答4:
Simple and easy
<?php
$browser = get_browser(null, true);
echo $browser['platform'];
?>
The docs say
Note:
In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system.
browscap.ini is not bundled with PHP, but you may find an up-to-date » php_browscap.ini file here.
While browscap.ini contains information on many browsers, it relies on user updates to keep the database current. The format of the file is fairly self-explanatory.
来源:https://stackoverflow.com/questions/7768324/detect-ios-version-with-php