브라우저 구분하는 php스크립트가 그누보드에서 동작하지 않는 이유 정보
브라우저 구분하는 php스크립트가 그누보드에서 동작하지 않는 이유본문
아래의 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();
}
댓글 전체

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';}
이부분에서 다르게 읽혀서 넘어가지는군요
같은 소스인데 다른 곳에서는 정상인데 다르게 넘어가다니.. 저녁에 시도해봐야 겠습니다..
그런데 print_r과 print_r2의 차이가 있나요?
그런데 print_r과 print_r2의 차이가 있나요?

print_r은 배열을 그냥 뿌리는거고 print_r2는 print_r 함수를 보기좋게 하기위해 그누보드에서 쓰는 함수인데요 배열을 편하게 볼 수 있게 되어있지요
그렇군요..
그누보드 알면 편한데 모르면 불편한 기능이 많이 있어서 날잡고 소스들을 다 뒤져봐야겠네요..
환경패스도 config.php외에 다른데서도 정의되있던걸 어제서야 발견한..
그누보드 알면 편한데 모르면 불편한 기능이 많이 있어서 날잡고 소스들을 다 뒤져봐야겠네요..
환경패스도 config.php외에 다른데서도 정의되있던걸 어제서야 발견한..