0

I'm trying to check if the user comes from the in-app Facebook browser or not because some functions on my website won't work properly if it's the Facebook browser.

I've found some JS snippets but I want to check it with PHP because I also filter some other things with PHP and don't want to use JS for that.

I'm using the Laravel 5.4 Framework but a normal PHP solution would be also great.

I've checked my HTTP_USER_AGENT with the Facebook browser and firefox/chrome browser and noticed some difference.

firefox gave me this back:

Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0

and facebook this:

Mozilla/5.0 (Linux; Android 6.0; HUAWEI VNS-L31 Build/HUAWEIVNS-L31; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/56.0.2924.87 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/116.0.0.17.69;] <<-- Important

And I noticed that at the end: [FB_IAB/FB4A;FBAV/116.0.0.17.69;]

So I've written this code:

        if (
            strpos($_SERVER["HTTP_USER_AGENT"], "FB_IAB") !== false ||
            strpos($_SERVER["HTTP_USER_AGENT"], "FB4A") !== false ||
            strpos($_SERVER["HTTP_USER_AGENT"], "FBAV") !== false
        ) 
        {
            return "its fb";
        }
        else {
            return "its not fb";
        }

And yes, it works for me. But I don't know if it works for other users like that. I also haven't worked with http_header - information. So do you think I'm on the safe side with this code or do I need to change something?

Thanks for your help and sorry for my bad English!

Sujal Patel
  • 2,199
  • 1
  • 19
  • 34
dwdawdawdaw
  • 211
  • 1
  • 5
  • 19

1 Answers1

0

I use https://github.com/hisorange/browser-detect Check for Facebook APP browser

use hisorange\BrowserDetect\Parser as Browser;

$userAgent = Browser::getUserAgentString();
$isFB = stripos($userAgent, 'FBAV') > 0;
Eduard Brokan
  • 531
  • 5
  • 7