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

后端 未结 10 2207
迷失自我
迷失自我 2020-11-28 07:27

How to detect if the user is browsing the page using webview for android or iOS?

There are various soluti

10条回答
  •  盖世英雄少女心
    2020-11-28 08:16

    Note: This solution is PHP-based. HTTP headers can be faked so this is not the nicest solution but you can have a start with this.

    //For iOS
    
    if ((strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile/') !== false) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari/') == false) {
        echo 'WebView';
    } else{
        echo 'Not WebView';
    }
    
    //For Android
    
    if ($_SERVER['HTTP_X_REQUESTED_WITH'] == "com.company.app") {
        echo 'WebView';
    } else{
        echo 'Not WebView';
    }
    

提交回复
热议问题