How to detect if the user is browsing the page using webview for android or iOS?
There are various soluti
This is the extended version of rhavendc's answer. It can be used for showing app install banner when a website is visited from browser, and hiding the banner when a website is opened in a webview.
$iPhoneBrowser = stripos($_SERVER['HTTP_USER_AGENT'], "iPhone");
$iPadBrowser = stripos($_SERVER['HTTP_USER_AGENT'], "iPad");
$AndroidBrowser = stripos($_SERVER['HTTP_USER_AGENT'], "Android");
$AndroidApp = $_SERVER['HTTP_X_REQUESTED_WITH'] == "com.company.app";
$iOSApp = (strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile/') !== false) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari/') == false);
if ($AndroidApp) {
echo "This is Android application, DONT SHOW BANNER";
}
else if ($AndroidBrowser) {
echo "This is Android browser, show Android app banner";
}
else if ($iOSApp) {
echo "This is iOS application, DONT SHOW BANNER";
}
else if($iPhoneBrowser || $iPadBrowser) {
echo "This is iOS browser, show iOS app banner";
}