7

CodeIgniter でユーザーが使用しているモバイル デバイスを検出できましたが、現在のモバイル デバイスが実行しているオペレーティング システムを検出できませんでした。

誰かが Android で動作する Samsung モバイル デバイスを使用していて、別のユーザーが通常の Java モバイル オペレーティング システムをまだ Samsung で使用しているとします。各ユーザーが使用しているオペレーティング システムを確認するにはどうすればよいですか?

4

6 に答える 6

19

http://mobiledetect.netからライブラリをダウンロードします Mobile_Detect.php を「ライブラリ」に入れます

メインコントローラー内部

public function index() {
    $this -> load -> library('Mobile_Detect');
    $detect = new Mobile_Detect();
    if ($detect->isMobile() || $detect->isTablet() || $detect->isAndroidOS()) {
        header("Location: ".$this->config->item('base_url')."/mobile"); exit;
    }
}

https://dwij.net/mobile-os-detection-in-php-codeigniter/でドキュメントを検索

于 2013-05-31T14:43:54.890 に答える
7

ライブラリをロードします。

$this->load->library('user_agent');

この関数を使用してモバイルを検出します

$mobile=$this->agent->is_mobile();
if($mobile){
  //your code
}
于 2016-12-15T12:19:05.573 に答える
1

https://github.com/serbanghita/Mobile-Detectからライブラリをダウンロードします Mobile_Detect.php を third_party ディレクトリにコピーします codeigniter でヘルパー クラスを作成します //この関数は、ユーザー エージェントの電話、タブレット、またはコンピューターを返します

if(!function_exists('is_MTC')):
    function is_MTC()
    {
        require(APPPATH .'third_party/Mobile_Detect.php');
        $detect = new Mobile_Detect;
        return ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
    }
endif;

ビューでは、 is_MTC 関数を直接呼び出してユーザー エージェントを確認できます
//これにより、ユーザー エージェントが出力されます

<?php echo is_MTC(); ?>

codeigniter ヘルパー関数について詳しく知るにはhttps://ellislab.com/codeigniter/user-guide/general/helpers.html

于 2015-08-13T07:04:18.610 に答える
0

セッションクラスを使用する場合、変数が組み込まれています。user_agent

于 2013-06-01T07:35:59.873 に答える
0

CodeIgniter には、codeigniter でのブラウザーまたはエージェント検出のサポートが組み込まれています。

コントローラー内では、次のサンプル コードを使用します。

$this->load->library('user_agent');
if ($this->agent->is_mobile()) {
    // Is a mobile browser
} else {
     // Is a Desktop/Bot User Agent
}
于 2016-12-19T13:31:14.800 に答える