2017-12-26 9 views
0

php私のウェブサイトがいつモバイル/タブレットで開かれているかを知るには、道が必要です。私は特定の各デバイスの設計(iPhone、Androidとタブレットの)携帯端末の入手方法

を必要とする私はこれを試してみたが、そのは正常に動作しません:

<?php if(stristr($_SERVER['HTTP_USER_AGENT'], "Mobile")) 
     { // if mobile browser ?>  
      <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/mobile.css" type="text/css" media="screen" /> 
     <?php } 

誰も私を助けることができますか?

+0

あなたはhttps://stackoverflow.com/questions/4117555/simplest-way-to-detect-a-mobile-deviceをチェックすることができます。既にansがあります –

答えて

1

あなたは、この目的のためのPHPライブラリを使用することができます。isMobile()isTablet()isiPhone()

https://github.com/serbanghita/Mobile-Detect 

は、これは、任意のデバイスなどを検出する機能をたくさん持っています唯一のPHP用など

<?php 
// include library file 
require_once 'Mobile_Detect.php'; 
$object = new Mobile_Detect; 


//Now detect device 
<?php 
// Return true or false based on your device 
$detect->isMobile(); 
$detect->isTablet(); 


<?php 
// Suppose you want to check for mobile environment. 
if ($detect->isMobile()) { 
    // Your code here. 
} 
0

上記のように両方のスタイルシートを使用してください。デバイスの幅が800ピクセル以下であれば、レンダリングにmobile.cssが使用されます。または、デフォルトではstyle.cssが使用されます。

関連する問題