2017-12-26 1 views
0

php 내 웹 사이트가 모바일/태블릿에서 열리는 것을 알 수있는 방법이 필요합니다. 나는 그것 제대로 작동하지php로 장치 소스 가져 오기

내가 이것을 시도했지만 한 각 디바이스 (아이폰, 안드로이드 태블릿의)를 특정 설계가 필요합니다

<?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

u는 https://stackoverflow.com/questions/4117555/simplest-way-to-detect-a-mobile- 장치를 확인할 수 있습니다. 이미 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
<link rel="stylesheet" href="style.css" /> 

<link rel="stylesheet" media="screen and (min-device-width: 800px)" href="mobile.css" /> 

위의 두 스타일 시트를 모두 사용하십시오. 따라서 장치 너비가 800px 이하이면 mobile.css가 렌더링에 사용됩니다. 아니면 기본적으로 style.css가 사용됩니다.