Detect in-app browser (WebView) with PHP / Javascript
I'm not sure about Android, but when you're using the iOS SDK's UIWebView
, it sends the name and version of your app as part of the user agent (YourApp/1.0
).
You can then use PHP to check if your in-app webview is being used or not:
if (strpos($_SERVER['HTTP_USER_AGENT'], 'YourApp/') !== false)
I think Android does something similar as well.
Solution code:
$isWebView = false;
if((strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile/') !== false) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari/') == false)) :
$isWebView = true;
elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH'])) :
$isWebView = true;
endif;
if(!$isWebView) :
// Android or iOS Webview
else :
// Normal Browser
endif;