Reputation: 699
Is there a way, in php, to know if a webpage is running in the facebook in-app browser?
When I post a link on facebook, I need to know, if the user views the webpage through the facebook App for iPad, or through facebook viewed on the iPad safari browser.
I know that i can detect the iPad, but this is not sufficient, since both the facebook App and the facebook through a browser will be running on an iPad.
Any suggestions?
Thanks
Upvotes: 0
Views: 1644
Reputation: 185
this is not complete solution but you can try like this for IOS (iPad/iPhone etc.) and Others
$internalBrowserOS = '';
if (strpos($_SERVER['HTTP_USER_AGENT'], 'FBAN') !== FALSE) {
if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone OS')) // or iPad
$internalBrowserOS = 'iPhone';
}else if(strpos($_SERVER['HTTP_USER_AGENT'], 'FB_IAB/FB4A') !== FALSE){
$internalBrowserOS = 'androidOrAnotherOne';
}
Upvotes: 1
Reputation: 2300
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';
}
Upvotes: 2
Reputation: 131
"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.
Source: Detect in-app browser (WebView) with PHP / Javascript
Hope this works for u
Upvotes: 1
Reputation: 131
Something like this might work for you...
if (
("standalone" in window.navigator) &&
!window.navigator.standalone
){
// .... code here ....
}
Check source:
Upvotes: 2