Detect In-App Browser (Webview) with PHP/Javascript

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.

How to check if user is using a web browser or web application with php?

If you mean that you want to check if the user is using a webview (from app Android/iOS) instead of a desktop, mobile browser, then you can check the user agent string

https://developer.chrome.com/multidevice/user-agent#webview_user_agent

If you’re attempting to differentiate between the WebView and Chrome for Android, you should look for the presence of the Version/X.X string in the WebView user-agent string. Don’t rely on the specific Chrome version number (for example, 30.0.0.0) as the version numbers changes with each release.

You could apparently use the same approach for iOS
Does UIWebView send the same User-Agent in the Request Headers as mobile Safari?

Get the user agen in PHP

$user_agent = $_SERVER['HTTP_USER_AGENT'];

UPDATE:

Have a look there, there is some more explanations
Detect in-app browser (WebView) with PHP / Javascript

Detect if user is using webview for android/iOS or a regular browser

Detecting browser for iOS devices is different from the Android one. For iOS devices you can do it by checking user agent using JavaScript:

var userAgent = window.navigator.userAgent.toLowerCase(),
safari = /safari/.test( userAgent ),
ios = /iphone|ipod|ipad/.test( userAgent );

if( ios ) {
if ( safari ) {
//browser
} else if ( !safari ) {
//webview
};
} else {
//not iOS
};

For Android devices, you need to do it through server side coding to check for a request header.

PHP:

if ($_SERVER['HTTP_X_REQUESTED_WITH'] == "your.app.id") {
//webview
} else {
//browser
}

JSP:

if ("your.app.id".equals(req.getHeader("X-Requested-With")) ){
//webview
} else {
//browser
}

Ref:detect ipad/iphone webview via javascript

PHP Detect page open via WebView

You could create a small mobile app which would only run on the mobile phones that you intend to support and the app would generate some temporary tokens and would POST them to the server. The session in the mobile browser would be registered to a WebSocket channel of the server and would update those tokens in real-time. This way, at least the given app is guaranteed to be run on a phone. And if the app is tied to a single session, then it is highly probable that the session would run on the same phone.

If you want to guarantee it, then you can create a browser extension which would communicate directly with your phone app on OS level.

How can i detect, if webpage is running in iPad in-app browser?

I too had this problem today.
I was comparing the Useragent-Strings and came up with a solution, that works for me.
Quick and dirty:

function check_ios_fb() {
$uagent = $_SERVER['HTTP_USER_AGENT'];
$return = false;
if(preg_match('/FBBV/i',$uagent))
{
if(preg_match('/iPhone/i',$uagent))
$return = true;
if(preg_match('/iPad/i',$uagent))
$return = true;
}
return $return;
}

if(check_ios_fb()) {
echo 'This page is viewed in the facebook inApp browser on iPhone or iPad';
} else {
echo 'This page is NOT viewed in the facebook inApp browser';
}

How to detect if using Android Browser or Android Native WebView Client

via PHP you can check the user-agent that is trying to access your web page. you can test with one of these.

if( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'your_android_app_package_name' ) {
//...Inject your javascript code

}

if( strpos($_SERVER['HTTP_USER_AGENT'], 'your_android_app_package_name/') !== false ){
//...Inject your javascript code.

}



Related Topics



Leave a reply



Submit