PHP code example of aknife / agent

1. Go to this page and download the library: Download aknife/agent library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aknife / agent example snippets


use Aknife\Agent\Agent;

Agent::lang('en'); // zh_cn / zh_tw / en


Agent::setUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/14G60 UCBrowser/11.7.7.1031 Mobile AliApp(TUnionSDK/0.1.20)');

Agent::ip('159.75.190.197');
/*
[
    'continent' => [
            'code' => 'AS',
            'name' => '亚洲',
    ],
    'country' => [
            'code' => 'CN',
            'name' => '中国',
    ],
    'region' => '广东省',
    'city' => '广州市',
]
*/

Agent::languages(); // return "zh-CN/zh-TW/en-US";

Agent::platform();  //  ['name'=>'Windows','version'=>'10']

$browser = Agent::browser(); // [ 'name'=>'Chrome','version'=>'74.0','full'=>'74.0.3729.131' ]


Agent::device();    //  ['model'=>'honor V10','brand'=>'Huawei','category'=>'smartphone']

Agent::robot(); // ['name'=>'Baidu Spider','category'=>'Search bot','checked'=>'false']

Agent::setIp('8.8.8.8');
Agent::isMobile();
Agent::isMobileApp();
Agent::isTablet();