아래의 php 스크립트가 그누보드에서만 동작하지 않는 이유를 알고 싶습니다..
다른 일반 페이지에서는 잘 동작하는 스크립트인데 그누보드에서는 왜인지 자꾸 무시되어 pc버전 화면으로 보여주네요..
if else로 모바일이면 모바일로, 아니라면 include문 실행으로 넘겨주는데 그래도 문제구요..
제 사이트 첫 페이지에서 사용중이던 파일 그대로 가져온건데 그누보드 안에서는 동작을 못하네요..
function getBrowser()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$bname = 'Unknown';
$platform = 'Unknown';
$version= "";
// 모바일 에이전트 목록
$mobile_agent = '/(iPod|iPhone|Android|BlackBerry|SymbianOS|SCH-M\d+|Opera Mini|Windows CE|Nokia|SonyEricsson|webOS|PalmOS)/';
//First get the platform?
if (preg_match('/linux/i', $u_agent)) { $platform = 'linux'; }
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) { $platform = 'mac'; }
elseif (preg_match('/windows|win32/i', $u_agent)) { $platform = 'windows'; }
elseif (preg_match($mobile_agent, $u_agent)) {$platform = 'mobile';}
// Next get the name of the useragent yes seperately and for good reason
if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent)) { $bname = 'Internet Explorer'; $ub = "MSIE"; }
elseif(preg_match('/Firefox/i',$u_agent)) { $bname = 'Mozilla Firefox'; $ub = "Firefox"; }
elseif(preg_match('/Chrome/i',$u_agent)) { $bname = 'Google Chrome'; $ub = "Chrome"; }
elseif(preg_match('/Safari/i',$u_agent)) { $bname = 'Apple Safari'; $ub = "Safari"; }
elseif(preg_match('/Opera/i',$u_agent)) { $bname = 'Opera'; $ub = "Opera"; }
elseif(preg_match('/Netscape/i',$u_agent)) { $bname = 'Netscape'; $ub = "Netscape"; }
// finally get the correct version number
$known = array('Version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) .
')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if (!preg_match_all($pattern, $u_agent, $matches)) {
// we have no matching number just continue
}
// see how many we have
$i = count($matches['browser']);
if ($i != 1) {
//we will have two since we are not using 'other' argument yet
//see if version is before or after the name
if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){ $version= $matches['version'][0]; }
else { $version= $matches['version'][1]; }
}
else { $version= $matches['version'][0]; }
// check if we have a number
if ($version==null || $version=="") {$version="?";}
return array('userAgent'=>$u_agent, 'name'=>$bname, 'version'=>$version, 'platform'=>$platform, 'pattern'=>$pattern);
}
$ua = getBrowser();
if($ua[platform] == 'mobile') {
Header("Location:m/index.php");
exit();
}
다른 일반 페이지에서는 잘 동작하는 스크립트인데 그누보드에서는 왜인지 자꾸 무시되어 pc버전 화면으로 보여주네요..
if else로 모바일이면 모바일로, 아니라면 include문 실행으로 넘겨주는데 그래도 문제구요..
제 사이트 첫 페이지에서 사용중이던 파일 그대로 가져온건데 그누보드 안에서는 동작을 못하네요..
function getBrowser()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$bname = 'Unknown';
$platform = 'Unknown';
$version= "";
// 모바일 에이전트 목록
$mobile_agent = '/(iPod|iPhone|Android|BlackBerry|SymbianOS|SCH-M\d+|Opera Mini|Windows CE|Nokia|SonyEricsson|webOS|PalmOS)/';
//First get the platform?
if (preg_match('/linux/i', $u_agent)) { $platform = 'linux'; }
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) { $platform = 'mac'; }
elseif (preg_match('/windows|win32/i', $u_agent)) { $platform = 'windows'; }
elseif (preg_match($mobile_agent, $u_agent)) {$platform = 'mobile';}
// Next get the name of the useragent yes seperately and for good reason
if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent)) { $bname = 'Internet Explorer'; $ub = "MSIE"; }
elseif(preg_match('/Firefox/i',$u_agent)) { $bname = 'Mozilla Firefox'; $ub = "Firefox"; }
elseif(preg_match('/Chrome/i',$u_agent)) { $bname = 'Google Chrome'; $ub = "Chrome"; }
elseif(preg_match('/Safari/i',$u_agent)) { $bname = 'Apple Safari'; $ub = "Safari"; }
elseif(preg_match('/Opera/i',$u_agent)) { $bname = 'Opera'; $ub = "Opera"; }
elseif(preg_match('/Netscape/i',$u_agent)) { $bname = 'Netscape'; $ub = "Netscape"; }
// finally get the correct version number
$known = array('Version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) .
')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
if (!preg_match_all($pattern, $u_agent, $matches)) {
// we have no matching number just continue
}
// see how many we have
$i = count($matches['browser']);
if ($i != 1) {
//we will have two since we are not using 'other' argument yet
//see if version is before or after the name
if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){ $version= $matches['version'][0]; }
else { $version= $matches['version'][1]; }
}
else { $version= $matches['version'][0]; }
// check if we have a number
if ($version==null || $version=="") {$version="?";}
return array('userAgent'=>$u_agent, 'name'=>$bname, 'version'=>$version, 'platform'=>$platform, 'pattern'=>$pattern);
}
$ua = getBrowser();
if($ua[platform] == 'mobile') {
Header("Location:m/index.php");
exit();
}
댓글 4개
print_r2($ua)로 확인해 보시면 왜 넘어가지 않는지 알 수 있으실것 같네요
if (preg_match('/linux/i', $u_agent)) { $platform = 'linux'; }
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) { $platform = 'mac'; }
elseif (preg_match('/windows|win32/i', $u_agent)) { $platform = 'windows'; }
elseif (preg_match($mobile_agent, $u_agent)) {$platform = 'mobile';}
이부분에서 다르게 읽혀서 넘어가지는군요
if (preg_match('/linux/i', $u_agent)) { $platform = 'linux'; }
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) { $platform = 'mac'; }
elseif (preg_match('/windows|win32/i', $u_agent)) { $platform = 'windows'; }
elseif (preg_match($mobile_agent, $u_agent)) {$platform = 'mobile';}
이부분에서 다르게 읽혀서 넘어가지는군요
게시글 목록
| 번호 | 제목 |
|---|---|
| 284508 | |
| 284499 | |
| 284492 | |
| 284490 | |
| 284484 | |
| 284481 | |
| 284478 | |
| 284476 | |
| 284474 | |
| 284472 | |
| 284470 | |
| 284458 | |
| 284457 | |
| 284454 | |
| 284453 | |
| 284447 | |
| 284446 | |
| 284444 | |
| 284441 | |
| 284440 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기