PHP mobile detection with new iPadOS/iOS 13 - php

I was wondering if there was any documentation or any new libraries which can detect the new iPadOS / iOS 13?
They used to output:
mozilla/5.0 (ipad; cpu iphone os 12_1_3 like mac os x) applewebkit/605.1.15 (khtml, like gecko) version/12.0 mobile/15e148 safari/604.1
But are now outputting:
mozilla/5.0 (macintosh; intel mac os x 10_15) applewebkit/605.1.15 (khtml, like gecko) version/13.0.1 safari/605.1.15
Has anyone come across this? Any new libraries to use?

Best I got as a solution was to use javascript:
// iPad check
if( (window.screen.height / window.screen.width == 1024 / 768) ||
(window.screen.height / window.screen.width == 1112 / 834) ||
(window.screen.height / window.screen.width == 1366 / 1024)
) {
// do stuff here
}
Not as perviously intended, but the best solution I have.

couldn't figure out a php way of doing it, but with javascript this seems to be the most appropriate yet
First detect if device is a mobile one. In recent iOS for iPad, this check returns false, which is practically wrong, but that's due to a desktop user agent.
Second test if the device has touch properties and see if platform contains the 'MacIntel' string
let isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
let isIOSMobile = navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
if (!isMobile && isIOSMobile ) {
//Desktop mode on IPad detected
alert("For the best experience we recommend switching Safari view to mobile");
}

This is a php solution and it works fine for me:
<?php
//Detect special conditions devices
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$iPadOS = stripos($_SERVER['HTTP_USER_AGENT'],"Macintosh");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
//TODO
if( $iPod || $iPhone || $iPad || $iPadOS || $Android){
//your methods
}

Related

How to deprecate support for Internet Explorer on my site [duplicate]

I am calling a function like the one below by click on divs with a certain class.
Is there a way I can check when starting the function if a user is using Internet Explorer and abort / cancel it if they are using other browsers so that it only runs for IE users ? The users here would all be on IE8 or higher versions so I would not need to cover IE7 and lower versions.
If I could tell which browser they are using that would be great but is not required.
Example function:
$('.myClass').on('click', function(event)
{
// my function
});
It's several years later, and the Edge browser now uses Chromium as its rendering engine.
Checking for IE 11 is still a thing, sadly.
Here is a more straightforward approach, as ancient versions of IE should be gone.
if (window.document.documentMode) {
// Do IE stuff
}
Here is my old answer (2014):
In Edge the User Agent String has changed.
/**
* detect IEEdge
* returns version of IE/Edge or false, if browser is not a Microsoft browser
*/
function detectIEEdge() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
// Edge => return version number
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
}
// other browser
return false;
}
Sample usage:
alert('IEEdge ' + detectIEEdge());
Default string of IE 10:
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)
Default string of IE 11:
Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko
Default string of Edge 12:
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0
Default string of Edge 13 (thx #DrCord):
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586
Default string of Edge 14:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/14.14300
Default string of Edge 15:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063
Default string of Edge 16:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299
Default string of Edge 17:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134
Default string of Edge 18 (Insider preview):
Mozilla/5.0 (Windows NT 10.0; Win64; x64; ServiceUI 14) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17730
Test at CodePen:
http://codepen.io/gapcode/pen/vEJNZN
Use below JavaScript method :
function msieversion()
{
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0) // If Internet Explorer, return version number
{
alert(parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))));
}
else // If another browser, return 0
{
alert('otherbrowser');
}
return false;
}
You may find the details on below Microsoft support site :
How to determine browser version from script
Update : (IE 11 support)
function msieversion() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer, return version number
{
alert(parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))));
}
else // If another browser, return 0
{
alert('otherbrowser');
}
return false;
}
If all you want to know is if the browser is IE or not, you can do this:
var isIE = false;
var ua = window.navigator.userAgent;
var old_ie = ua.indexOf('MSIE ');
var new_ie = ua.indexOf('Trident/');
if ((old_ie > -1) || (new_ie > -1)) {
isIE = true;
}
if ( isIE ) {
//IE specific code goes here
}
Update 1: A better method
I recommend this now. It is still very readable and is far less code :)
var ua = window.navigator.userAgent;
var isIE = /MSIE|Trident/.test(ua);
if ( isIE ) {
//IE specific code goes here
}
Thanks to JohnnyFun in the comments for the shortened answer :)
Update 2: Testing for IE in CSS
Firstly, if you can, you should use #supports statements instead of JS for checking if a browser supports a certain CSS feature.
.element {
/* styles for all browsers */
}
#supports (display: grid) {
.element {
/* styles for browsers that support display: grid */
}
}
(Note that IE doesn't support #supports at all and will ignore any styles placed inside an #supports statement.)
If the issue can't be resolved with #supports then you can do this:
// JS
var ua = window.navigator.userAgent;
var isIE = /MSIE|Trident/.test(ua);
if ( isIE ) {
document.documentElement.classList.add('ie')
}
/* CSS */
.element {
/* styles that apply everywhere */
}
.ie .element {
/* styles that only apply in IE */
}
(Note: classList is relatively new to JS and I think, out of the IE browsers, it only works in IE11. Possibly also IE10.)
If you are using SCSS (Sass) in your project, this can be simplified to:
/* SCSS (Sass) */
.element {
/* styles that apply everywhere */
.ie & {
/* styles that only apply in IE */
}
}
Update 3: Adding Microsoft Edge (not recommended)
If you also want to add Microsoft Edge into the list, you can do the following. However I do not recommend it as Edge is a much more competent browser than IE.
var ua = window.navigator.userAgent;
var isIE = /MSIE|Trident|Edge\//.test(ua);
if ( isIE ) {
//IE & Edge specific code goes here
}
This returns true for any version of Internet Explorer:
function isIE(userAgent) {
userAgent = userAgent || navigator.userAgent;
return userAgent.indexOf("MSIE ") > -1 || userAgent.indexOf("Trident/") > -1 || userAgent.indexOf("Edge/") > -1;
}
The userAgent parameter is optional and it defaults to the browser's user agent.
You can use the navigator object to detect user-navigator, you don't need jquery for it, the 4 comments below are already included so this snippet works as expected
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent) || navigator.userAgent.indexOf("Trident/") > -1 ){
// Do stuff with Internet-Exploders ... :)
}
http://www.javascriptkit.com/javatutors/navigator.shtml
This is how the Angularjs team is doing it (v 1.6.5):
var msie, // holds major version number for IE, or NaN if UA is not IE.
// Support: IE 9-11 only
/**
* documentMode is an IE-only property
* http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx
*/
msie = window.document.documentMode;
Then there are several lines of code scattered throughout using it as a number such as
if (event === 'input' && msie <= 11) return false;
and
if (enabled && msie < 8) {
You can simply do this:
var isIE = window.document.documentMode ? true : false; // this variable will hold if the current browser is IE
I know the question is old but if someone scrolled that far they can see the simple answer :)
Method 01:
$.browser was deprecated in jQuery version 1.3 and removed in 1.9
if ( $.browser.msie) {
alert( "Hello! This is IE." );
}
Method 02:
Using Conditional Comments
<!--[if gte IE 8]>
<p>You're using a recent version of Internet Explorer.</p>
<![endif]-->
<!--[if lt IE 7]>
<p>Hm. You should upgrade your copy of Internet Explorer.</p>
<![endif]-->
<![if !IE]>
<p>You're not using Internet Explorer.</p>
<![endif]>
Method 03:
/**
* Returns the version of Internet Explorer or a -1
* (indicating the use of another browser).
*/
function getInternetExplorerVersion()
{
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
function checkVersion()
{
var msg = "You're not using Internet Explorer.";
var ver = getInternetExplorerVersion();
if ( ver > -1 )
{
if ( ver >= 8.0 )
msg = "You're using a recent copy of Internet Explorer."
else
msg = "You should upgrade your copy of Internet Explorer.";
}
alert( msg );
}
Method 04:
Use JavaScript/Manual Detection
/*
Internet Explorer sniffer code to add class to body tag for IE version.
Can be removed if your using something like Modernizr.
*/
var ie = (function ()
{
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i>< ![endif]-->',
all[0]);
//append class to body for use with browser support
if (v > 4)
{
$('body').addClass('ie' + v);
}
}());
Reference Link
Using the answers above; simple & condensed returning Boolean:
var isIE = /(MSIE|Trident\/|Edge\/)/i.test(navigator.userAgent);
I just wanted to check if the browser was IE11 or older, because well, they're crap.
function isCrappyIE() {
var ua = window.navigator.userAgent;
var crappyIE = false;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {// IE 10 or older => return version number
crappyIE = true;
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {// IE 11 => return version number
crappyIE = true;
}
return crappyIE;
}
if(!isCrappyIE()){console.table('not a crappy browser);}
function detectIE() {
var ua = window.navigator.userAgent;
var ie = ua.search(/(MSIE|Trident|Edge)/);
return ie > -1;
}
Using modernizr
Modernizr.addTest('ie', function () {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ') > 0;
var ie11 = ua.indexOf('Trident/') > 0;
var ie12 = ua.indexOf('Edge/') > 0;
return msie || ie11 || ie12;
});
Or this really short version, returns true if the browsers is Internet Explorer:
function isIe() {
return window.navigator.userAgent.indexOf("MSIE ") > 0
|| !!navigator.userAgent.match(/Trident.*rv\:11\./);
}
Try this if you are using jquery version >=1.9,
var browser;
jQuery.uaMatch = function (ua) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
/(webkit)[ \/]([\w.]+)/.exec(ua) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
/(msie) ([\w.]+)/.exec(ua) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
/(Trident)[\/]([\w.]+)/.exec(ua) || [];
return {
browser: match[1] || "",
version: match[2] || "0"
};
};
// Don't clobber any existing jQuery.browser in case it's different
if (!jQuery.browser) {
matched = jQuery.uaMatch(navigator.userAgent);
browser = {};
if (matched.browser) {
browser[matched.browser] = true;
browser.version = matched.version;
}
// Chrome is Webkit, but Webkit is also Safari.
if (browser.chrome) {
browser.webkit = true;
} else if (browser.webkit) {
browser.safari = true;
}
jQuery.browser = browser;
}
If using jQuery version <1.9 ($.browser was removed in jQuery 1.9) use the following code instead:
$('.myClass').on('click', function (event) {
if ($.browser.msie) {
alert($.browser.version);
}
});
Yet another simple (yet human readable) function to detect if the browser is IE or not (ignoring Edge, which isn't bad at all):
function isIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE '); // IE 10 or older
var trident = ua.indexOf('Trident/'); //IE 11
return (msie > 0 || trident > 0);
}
If you don't want to use the useragent, you could also just do this for checking if the browser is IE. The commented code actually runs in IE browsers and turns the "false" to "true".
var isIE = /*#cc_on!#*/false;
if(isIE){
//The browser is IE.
}else{
//The browser is NOT IE.
}
I know this is an old question, but in case anyone comes across it again and has issues with detecting IE11, here is a working solution for all current versions of IE.
var isIE = false;
if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
isIE = true;
}
i've used this
function notIE(){
var ua = window.navigator.userAgent;
if (ua.indexOf('Edge/') > 0 ||
ua.indexOf('Trident/') > 0 ||
ua.indexOf('MSIE ') > 0){
return false;
}else{
return true;
}
}
Necromancing.
In order to not depend on the user-agent string, just check for a few properties:
if (document.documentMode)
{
console.log('Hello Microsoft IE User!');
}
if (!document.documentMode && window.msWriteProfilerMark) {
console.log('Hello Microsoft Edge User!');
}
if (document.documentMode || window.msWriteProfilerMark)
{
console.log('Hello Microsoft User!');
}
if (window.msWriteProfilerMark)
{
console.log('Hello Microsoft User in fewer characters!');
}
Also, this detects the new Chredge/Edgium (Anaheim):
function isEdg()
{
for (var i = 0, u="Microsoft", l =u.length; i < navigator.plugins.length; i++)
{
if (navigator.plugins[i].name != null && navigator.plugins[i].name.substr(0, l) === u)
return true;
}
return false;
}
And this detects chromium:
function isChromium()
{
for (var i = 0, u="Chromium", l =u.length; i < navigator.plugins.length; i++)
{
if (navigator.plugins[i].name != null && navigator.plugins[i].name.substr(0, l) === u)
return true;
}
return false;
}
And this Safari:
if(window.safari)
{
console.log("Safari, yeah!");
}
#SpiderCode's solution does not work with IE 11. Here is the best solution that I used henceforth in my code where I need browser detection for particular feature.
IE11 no longer reports as MSIE, according to this list of changes, it's intentional to avoid mis-detection.
What you can do if you really want to know it's IE is to detect the Trident/ string in the user agent if navigator.appName returns Netscape, something like (the untested);
Thanks to this answer
function isIE()
{
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
else if (navigator.appName == 'Netscape')
{
var ua = navigator.userAgent;
var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv == -1 ? false: true;
}
Many answers here, and I'd like to add my input. IE 11 was being such an ass concerning flexbox (see all its issues and inconsistencies here) that I really needed an easy way to check if a user is using any IE browser (up to and including 11) but excluding Edge, because Edge is actually pretty nice.
Based on the answers given here, I wrote a simple function returning a global boolean variable which you can then use down the line. It's very easy to check for IE.
var isIE;
(function() {
var ua = window.navigator.userAgent,
msie = ua.indexOf('MSIE '),
trident = ua.indexOf('Trident/');
isIE = (msie > -1 || trident > -1) ? true : false;
})();
if (isIE) {
alert("I am an Internet Explorer!");
}
This way you only have to do the look up once, and you store the result in a variable, rather than having to fetch the result on each function call. (As far as I know you don't even have to wait for document ready to execute this code as the user-agent is not related to the DOM.)
Below I found elegant way of doing this while googling ---
/ detect IE
var IEversion = detectIE();
if (IEversion !== false) {
document.getElementById('result').innerHTML = 'IE ' + IEversion;
} else {
document.getElementById('result').innerHTML = 'NOT IE';
}
// add details to debug result
document.getElementById('details').innerHTML = window.navigator.userAgent;
/**
* detect IE
* returns version of IE or false, if browser is not Internet Explorer
*/
function detectIE() {
var ua = window.navigator.userAgent;
// Test values; Uncomment to check result …
// IE 10
// ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)';
// IE 11
// ua = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
// IE 12 / Spartan
// ua = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0';
// Edge (IE 12+)
// ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586';
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
// Edge (IE 12+) => return version number
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
}
// other browser
return false;
}
Update to SpiderCode's answer to fix issues where the string 'MSIE' returns -1 but it matches 'Trident'. It used to return NAN, but now returns 11 for that version of IE.
function msieversion() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > -1) {
return ua.substring(msie + 5, ua.indexOf(".", msie));
} else if (navigator.userAgent.match(/Trident.*rv\:11\./)) {
return 11;
} else {
return false;
}
}
I landed on this page in 2020, and I see that till IE5 all userAgent string have Trident, I'm not sure if they have changed anything. So checking only for Trident in the userAgent worked for me.
var isIE = navigator.userAgent.indexOf('Trident') > -1;
This is another way to detect IE without trying to look at the User-Agent:
var usingIE="__IE_DEVTOOLBAR_CONSOLE_EVAL_ERROR" in document;
alert("You are"+(usingIE?"":"n't")+" using Internet Explorer.");
I happened to find this by accident when I was testing if my site worked on IE, and I went to the debugger and clicked the folder icon. It has my scripts, and also a Dynamic Scripts folder that I didn't have. I opened it and found lots of browsertools.library.js files. Inside them I found stuff like:
document.__IE_DEVTOOLBAR_CONSOLE_EVAL_RESULT = undefined;
document.__IE_DEVTOOLBAR_CONSOLE_EVAL_ERROR = false;
document.__IE_DEVTOOLBAR_CONSOLE_EVAL_ERRORCODE = undefined;
try{
document.__IE_DEVTOOLBAR_CONSOLE_EVAL_RESULT = eval("\r\n//# sourceURL=browsertools://browsertools.library.js");
}
catch( eObj ){
document.__IE_DEVTOOLBAR_CONSOLE_EVAL_ERRORCODE = eObj.number;
document.__IE_DEVTOOLBAR_CONSOLE_EVAL_RESULT = eObj.message || eObj.description || eObj.toString();
document.__IE_DEVTOOLBAR_CONSOLE_EVAL_ERROR = true;
}
So I used these to test if the user's browser was IE. Just note this only works if you want to know if they have IE, not exactly what version of IE they have.
You can dectect all Internet Explorer (Last Version Tested 12).
<script>
var $userAgent = '';
if(/MSIE/i['test'](navigator['userAgent'])==true||/rv/i['test'](navigator['userAgent'])==true||/Edge/i['test'](navigator['userAgent'])==true){
$userAgent='ie';
} else {
$userAgent='other';
}
alert($userAgent);
</script>
See here https://jsfiddle.net/v7npeLwe/
function msieversion() {
var ua = window.navigator.userAgent;
console.log(ua);
var msie = ua.indexOf("MSIE ");
if (msie > -1 || navigator.userAgent.match(/Trident.*rv:11\./)) {
// If Internet Explorer, return version numbe
// You can do what you want only in IE in here.
var version_number=parseInt(ua.substring(msie + 5, ua.indexOf(".", msie)));
if (isNaN(version_number)) {
var rv_index=ua.indexOf("rv:");
version_number=parseInt(ua.substring(rv_index+3,ua.indexOf(".",rv_index)));
}
console.log(version_number);
} else {
//other browser
console.log('otherbrowser');
}
}
You should see the result in console, please use chrome Inspect.
I've placed this code in the document ready function and it only triggers in internet explorer. Tested in Internet Explorer 11.
var ua = window.navigator.userAgent;
ms_ie = /MSIE|Trident/.test(ua);
if ( ms_ie ) {
//Do internet explorer exclusive behaviour here
}
This only work below IE 11 version.
var ie_version = parseInt(window.navigator.userAgent.substring(window.navigator.userAgent.indexOf("MSIE ") + 5, window.navigator.userAgent.indexOf(".", window.navigator.userAgent.indexOf("MSIE "))));
console.log("version number",ie_version);
JavaScript function to detect the version of Internet Explorer or Edge
function ieVersion(uaString) {
uaString = uaString || navigator.userAgent;
var match = /\b(MSIE |Trident.*?rv:|Edge\/)(\d+)/.exec(uaString);
if (match) return parseInt(match[2])
}

get_browser() returns Chrome when using Opera browser in Samsung galaxy tab

Hi Im tracking the browsers of the users who are visiting my site with the use of browsecap.ini
the following is the code that i use
if(isset($message['HTTP_USER_AGENT'])){
$get_browser = get_browser($message['HTTP_USER_AGENT'], true);
if (!empty($get_browser)){
$str_values.='".mysql_real_escape_string($get_browser['comment'])."'
But when the users who use the opera browser in a galaxy tab are shown as chrome browser users
can anybody help me to rectify this isse
P.S - Im using the lite version of browsecap.ini file
You kindly provided me with a sample UA string of the offending mobile Opera browser:
Mozilla/5.0 (Linux; Android 4.1.2; GT-P3100 Build/JZO54K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.81 Safari/537.36 OPR/28.0.1764.90386
and the regex returned by get_browser() on that UA is:
$^mozilla/5.0 (.*linux.android.4.1.) applewebkit/.* (khtml, like gecko).*chrome/41..safari/.$
which didn't detect the Opera browser at all. However, I found this function that you can also run to get the browser name. The very first check is for that "OPR/" fragment of the UA string.
When run with the test UA supplied above, the output is "Opera".
<?php
function ExactBrowserName() {
$ExactBrowserNameUA=$_SERVER['HTTP_USER_AGENT'];
If (strpos(strtolower($ExactBrowserNameUA), "safari/") and strpos(strtolower($ExactBrowserNameUA), "opr/")) {
// OPERA
$ExactBrowserNameBR="Opera";
} ElseIf (strpos(strtolower($ExactBrowserNameUA), "safari/") and strpos(strtolower($ExactBrowserNameUA), "chrome/")) {
// CHROME
$ExactBrowserNameBR="Chrome";
} ElseIf (strpos(strtolower($ExactBrowserNameUA), "msie")) {
// INTERNET EXPLORER
$ExactBrowserNameBR="Internet Explorer";
} ElseIf (strpos(strtolower($ExactBrowserNameUA), "firefox/")) {
// FIREFOX
$ExactBrowserNameBR="Firefox";
} ElseIf (strpos(strtolower($ExactBrowserNameUA), "safari/") and strpos(strtolower($ExactBrowserNameUA), "opr/")==false and strpos(strtolower($ExactBrowserNameUA), "chrome/")==false) {
// SAFARI
$ExactBrowserNameBR="Safari";
} Else {
// OUT OF DATA
$ExactBrowserNameBR="OUT OF DATA";
};
return $ExactBrowserNameBR;
}
?>
Ref: How to get exact browser name and version?

why does the $_SERVER['HTTP_USER_AGENT'] not return MSIE [duplicate]

This question already has an answer here:
Why do Chrome and IE put "Mozilla 5.0" in the User-Agent they send to the server? [duplicate]
(1 answer)
Closed 8 years ago.
I am trying to do some php browser testing. When I looked at
$_SERVER['HTTP_USER_AGENT'
I found that it returned this:
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
even though I was on IE 11.
When I was on Chrome, it returned this:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36
Which makes more sense. Why is there no MSIE in the IE, and how can I target it?
"Trident" is the layout engine for MSIE 11. As you can see there, while you were on IE 11 it loaded as Trident/7.0; rv:11.0) Just like when you were on Chrome it loaded as AppleWebKit/537.36.
If you're looking to get more information about the browser, you could always use PHP's get_browser() function.
its because the MSIE from 8 marks its version through TRIDENT. Ive found this script time ago. It also detects if the browser is in compatibility mode. It may help you, but its in JS:
EDIT: a simple search made i found the original code in github.
var ieUserAgent = {
init: function () {
// Get the user agent string
var ua = navigator.userAgent;
this.compatibilityMode = false;
// Detect whether or not the browser is IE
var ieRegex = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (ieRegex.exec(ua) == null)
this.exception = "The user agent detected does not contain Internet Explorer.";
// Get the current "emulated" version of IE
this.renderVersion = parseFloat(RegExp.$1);
this.version = this.renderVersion;
// Check the browser version with the rest of the agent string to detect compatibility mode
if (ua.indexOf("Trident/7.0") > -1) {
if (ua.indexOf("MSIE 7.0") > -1) {
this.compatibilityMode = true;
}
this.version = 11; // IE 11
}
else if (ua.indexOf("Trident/6.0") > -1) {
if (ua.indexOf("MSIE 7.0") > -1) {
this.compatibilityMode = true;
}
this.version = 10; // IE 10
}
else if (ua.indexOf("Trident/5.0") > -1) {
if (ua.indexOf("MSIE 7.0") > -1) {
this.compatibilityMode = true;
}
this.version = 9; // IE 9
}
else if (ua.indexOf("Trident/4.0") > -1) {
if (ua.indexOf("MSIE 7.0") > -1) {
this.compatibilityMode = true;
}
this.version = 8; // IE 8
}
else if (ua.indexOf("MSIE 7.0") > -1)
this.version = 7; // IE 7
else
this.version = 6; // IE 6
}
};
// Initialize the ieUserAgent object
ieUserAgent.init();
$(document).ready(function() {
if(ieUserAgent.compatibilityMode) {
//do stuff
}
if(ieUserAgent.version == 6) {
//do stuff
}
});
IE11 drops the "MSIE" portion of the user agent string. It doesn't stop there, either - navigator.appName will return Netscape and navigator.product returns Gecko.
The likely cause for this is that IE11 has caught up enough with modern web standards that Microsoft doesn't want it triggering the old if(IE) { // shitty simpler website } handlers all over the web. They want it seeing the same full-featured version Chrome/Firefox see.

php make google and facebook access my site

I want to access my site from ONLY my country and I want to google and facebook can access to my site. So I looked to the these pages:
https://developers.facebook.com/docs/sharing/best-practices#crawl
https://support.google.com/webmasters/answer/1061943?hl=en
And I writed this php code:
<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
if (!preg_match("/facebook/", $agent) && !preg_match("/bingbot/", $agent) && !preg_match("/Googlebot/", $agent) && $agent != 'Facebot')
{
$country = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
if($country != 'AZ')
{
$error = 'Sorry, we can only serve to Azerbaijan!';
include('error.php');
die;
}
}
?>
It works on facebook. But when I want to get my page speed results with google, i get "Sorry, we can only serve to Azerbaijan!" error
This is the one of the user agent of Google Page Speed Insight
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko; Google Page Speed Insights) Chrome/27.0.1453 Safari/537.36
Change this
!preg_match("/Googlebot/", $agent)
to this
!preg_match("/Google(bot| Page Speed Insights)/", $agent)

Detect iOS version lower than iOS 8 php

If been searching for a while but don't find any good solution. I need to detect the iOS version so that I can decide whether to show some part of the website or not. Additionally this content should be shown on any non MobileSafari browser.
So basically:
If iOS and if version < iOS 8 than do nothing;
Else show content
With lots of thanks to #Lucas1 and #Daan I came up with this :)
<?php
if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strpos($_SERVER['HTTP_USER_AGENT'],'iPad' ) || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod' ) !== false){
if (strpos($_SERVER['HTTP_USER_AGENT'], 'OS 8_0') !== false) {
echo "content here on ios";
}
else{echo "sorry no content for you";}
}
else {
echo "content here";
}?>
The HTTP_USER_AGENT will return the following:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 8_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 8, do the following:
<?php if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone OS 8_0') !== false) { };?>

Categories