How to recognize Facebook User-Agent

后端 未结 11 1355
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 15:35

When sharing one of my pages on FB, I want to display something different. Problem is, I prefer not to use the og: elements, but to recognize FB user-agent.

What is

11条回答
  •  攒了一身酷
    2020-11-27 15:48

    Another generic approach in PHP

    $agent = $_SERVER['HTTP_USER_AGENT'];
    $agent = trim($agent);
    $agent = strtolower($agent);
    if (
    strpos($agent,'facebookexternalhit/1.1')===0
    || strpos($agent,'facebookexternalhit/1.0')===0
    ){
        //probably facebook
    }else{
        //probably not facebook
    }
    

提交回复
热议问题