cari

Rumah  >  Soal Jawab  >  teks badan

php - Bagaimana untuk menentukan sama ada akses datang dari PC atau mudah alih?

Penghakiman adalah terutamanya dari sisi PC, kerana beberapa operasi mesti dilakukan pada komputer
Ia adalah dari sisi mudah alih, menyembunyikan beberapa fungsi.

过去多啦不再A梦过去多啦不再A梦2742 hari yang lalu697

membalas semua(5)saya akan balas

  • 迷茫

    迷茫2017-05-27 17:44:54

    Kelas pembantu adalah seperti berikut:
    Prinsipnya adalah untuk mengesahkan pengepala

    <?php
    /**
     * Created by PhpStorm.
     * User: QQ: 1716771371
     * oschina:http://git.oschina.net/zhaojunlike
     * github: http://github.com/zhaojunlike
     * Date: 2016/8/14
     * Time: 8:55
     */
    
    namespace Common\Helper;
    
    
    class MobileHelper
    {
    
    
        static private $instance;
    
    
        public static function isMobile()
        {
            $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';
            $mobile_browser = '0';
            if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))
                $mobile_browser++;
            if ((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']), 'application/vnd.wap.xhtml+xml') !== false))
                $mobile_browser++;
            if (isset($_SERVER['HTTP_X_WAP_PROFILE']))
                $mobile_browser++;
            if (isset($_SERVER['HTTP_PROFILE']))
                $mobile_browser++;
            $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4));
            $mobile_agents = array(
                'w3c ', 'acs-', 'alav', 'alca', 'amoi', 'audi', 'avan', 'benq', 'bird', 'blac',
                'blaz', 'brew', 'cell', 'cldc', 'cmd-', 'dang', 'doco', 'eric', 'hipt', 'inno',
                'ipaq', 'java', 'jigs', 'kddi', 'keji', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-',
                'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp', 'nec-',
                'newt', 'noki', 'oper', 'palm', 'pana', 'pant', 'phil', 'play', 'port', 'prox',
                'qwap', 'sage', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh-', 'shar',
                'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-',
                'tosh', 'tsm-', 'upg1', 'upsi', 'vk-v', 'voda', 'wap-', 'wapa', 'wapi', 'wapp',
                'wapr', 'webc', 'winw', 'winw', 'xda', 'xda-'
            );
            if (in_array($mobile_ua, $mobile_agents))
                $mobile_browser++;
            if (strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)
                $mobile_browser++;
            // Pre-final check to reset everything if the user is on Windows
            if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)
                $mobile_browser = 0;
            // But WP7 is also Windows, with a slightly different characteristic
            if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)
                $mobile_browser++;
            if ($mobile_browser > 0)
                return true;
            else
                return false;
        }
    }

    balas
    0
  • 天蓬老师

    天蓬老师2017-05-27 17:44:54

    Mobile_Detect是轻量级php库通过User-agent和特定的人HttpHakim mengikut kepala:

    • Mobile_Detect

    balas
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-27 17:44:54

    function is_mobile() {
        if(empty($_SERVER['HTTP_USER_AGENT']))return false;
        $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
        $mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte");
        $is_mobile = false;
        foreach ($mobile_agents as $device) {
            if (stristr($user_agent, $device)) {
                $is_mobile = true;
                break;
            }
        }
        return $is_mobile;
    }

    balas
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-27 17:44:54

    Siarkan kod dalam THINKcmf

    /**
     * 判断是否为手机访问
     * @return  boolean
     */
    function sp_is_mobile() {
        static $sp_is_mobile;
    
        if ( isset($sp_is_mobile) )
            return $sp_is_mobile;
    
        if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
            $sp_is_mobile = false;
        } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
                || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
                || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
                || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
                || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
                || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
                || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
            $sp_is_mobile = true;
        } else {
            $sp_is_mobile = false;
        }
    
        return $sp_is_mobile;
    }
    
    /**
     * 判断是否为微信访问
     * @return boolean
     */
    function sp_is_weixin(){
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
            return true;
        }
        return false;
    }
    

    Sudah tentu, jika anda masih perlu menilai Android atau iOS, terdapat kaedah mudah Sesuaikan nilai HTTP_USER_AGENT pada bahagian mudah alih, dan kemudian dapatkan $_SERVER['HTTP_USER_AGENT'] daripada pelayan untuk menentukan sama ada watak ini adalah Wujud

    $user_agent = $_SERVER['HTTP_USER_AGENT'];
                if (stripos($user_agent, 'my_webapp') !== false) {
                    $this->assign("is_webapp", true);
            }

    balas
    0
  • phpcn_u1582

    phpcn_u15822017-05-27 17:44:54

    Saya menjawab soalan ini dalam kesalahan segmen, dan penanya berkata ia sah pada masa itu: /q/101...

    balas
    0
  • Batalbalas