HTML [JS/PHP/ASP] 브라우저 정보로 홈페이지 이동하기
페이지 정보
본문
브라우저 Agent 정보 https://www.happyjung.com/lecture/1564
브라우저 정보로 다른 내용 보이기https://www.happyjung.com/bbs/board.php?bo_table=lecture&wr_id=1661
1. 자바스크립트로 제어하기
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
// 브라우저 정보로 홈페이지 이동하기
if( (navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/iPod/i)) ||
(navigator.userAgent.match(/Android/i)) ||
(navigator.userAgent.match(/Blackberry/i)) ||
(navigator.userAgent.match(/BB10/i)) ||
(navigator.userAgent.match(/OperaMobi/i)) ||
(navigator.userAgent.match(/Opera Mini/i)) ||
(navigator.userAgent.match(/IEMobile/i)) ||
(navigator.userAgent.match(/Jasmine/i)) ||
(navigator.userAgent.match(/Fennec/i)) ||
(navigator.userAgent.match(/Blazer/i)) ||
(navigator.userAgent.match(/Minimo/i)) ||
(navigator.userAgent.match(/MOT-/i)) ||
(navigator.userAgent.match(/Nokia/i)) ||
(navigator.userAgent.match(/SAMSUNG/i)) ||
(navigator.userAgent.match(/Polaris/i)) ||
(navigator.userAgent.match(/LG-/i)) ||
(navigator.userAgent.match(/SonyEricsson/i)) ||
(navigator.userAgent.match(/SIE-/i)) ||
(navigator.userAgent.match(/AUDIOVOX/i)) ||
(navigator.userAgent.match(/mobile/i)) ||
(navigator.userAgent.match(/webOS/i)) ) {
// 모바일 주소 표시줄 숨기기
window.addEventListener('load', function(){ setTimeout(scrollTo, 0, 0, 1); }, false);
// 모바일 버전으로 페이지 이동
document.location = "/mobile/";
}else{
// 웹 버전으로 페이지 이동
document.location = "/web/";
}
//-->
</script>
2. PHP 코드로 제어하기
2-1. < 사용예1 >
<?php
// 브라우저 정보로 홈페이지 이동하기
//preg_match 가 오류날때 즉, php 버전이 낮을 경우엔 eregi 를 써야 합니다.
if(preg_match('/(phone|samsung|lgtel|mobile|[^A]skt|nokia|blackberry|BB10|android|sony|SonyEricsson|DoCoMo|JVodafone|SoftBank|MOT-|UP.Browser|KDDI|WILLCOM|SHARP|DDIPOCKET|PSP|SymbianOS|Windows CE|webOS|PalmOS)/i', $_SERVER['HTTP_USER_AGENT']))
{
$URL= "http://m.happyjung.com/";
echo "<script type=\"text/javascript\">\n";
echo "<!--\n";
//echo "location.href = '". $URL."';\n"; // 현재창으로 전송
echo "parent.location.href='". $URL."';\n"; // 부모창으로 전송
echo "//-->\n";
echo "</script>\n";
exit;
}
$URL= "https://www.happyjung.com/";
echo "<script type=\"text/javascript\">\n";
echo "<!--\n";
//echo "location.href = '". $URL."';\n"; // 현재창으로 전송
echo "parent.location.href='". $URL ."';\n"; // 부모창으로 전송
echo "//-->\n";
echo "</script>\n";
?>
2-2. < 사용예2 >
<?php
// 브라우저 정보로 홈페이지 이동하기
if(preg_match('/(phone|samsung|lgtel|mobile|[^A]skt|nokia|blackberry|BB10|android|sony|SonyEricsson|DoCoMo|JVodafone|SoftBank|MOT-|UP.Browser|KDDI|WILLCOM|SHARP|DDIPOCKET|PSP|SymbianOS|Windows CE|webOS|PalmOS)/i', $_SERVER['HTTP_USER_AGENT']))
{ // 스마트폰 종류 확인
$hp_mobile_check="y";
}
?>
<?php if ($hp_mobile_check=="y") { ?>모바일일때<?php } ?>
3. ASP 코드로 제어하기
[ 방법.1 ]
<%
'Request.ServerVariables("HTTP_USER_AGENT") ' 접속자의 에이젼트 정보를 얻는함수
Dim arr_Browser, user_agent, i
arr_Browser = array("iPhone", "iPod", "IEMobile", "Mobile", "lgtelecom", "PPC", "BlackBerry", "BB10", "SCH-", "SPH-", "LG-", "CANU", "IM-" ,"EV-", "Nokia")
for i = 0 to Ubound(arr_Browser)
user_agent = arr_Browser(i)
If InStr(Request.ServerVariables("HTTP_USER_AGENT"), user_agent) = 0 then
response.redirect("http://m.happyjung.com/m/index.asp")
end if
next
%>
[ 방법.2 ]
<%
dim device, device2
dim strUserAgent ' 브라우저 타입
dim IE, IE6, IE7, IE8, IE9, IE10, IE11, Opera, Opera5, ChromeSafari, Chrome, Safari, Firefox, OtherBrowser
dim Adroid, Android
dim mobile_check
' 모바일인지, pc 인지 확인용
device=request("device")
'클라이언트 브라우저 환경 감지
strUserAgent = UCase(cstr(request.ServerVariables("HTTP_USER_AGENT")))
'response.write strUserAgent
IE = FALSE
IE6 = FALSE
IE7 = FALSE
IE8 = FALSE
IE9 = FALSE
IE10 = FALSE
IE11 = FALSE
if InStr(strUserAgent, "MSIE 6") then
IE = TRUE
IE6 = TRUE
elseif InStr(strUserAgent, "MSIE 7") then
IE = TRUE
IE7 = TRUE
elseif InStr(strUserAgent, "MSIE 8") then
IE = TRUE
IE8 = TRUE
elseif InStr(strUserAgent, "MSIE 9") then
IE = TRUE
IE9 = TRUE
elseif InStr(strUserAgent, "MSIE 10") then
IE = TRUE
IE10 = TRUE
elseif InStr(strUserAgent, "v:11") then
IE = TRUE
IE11 = TRUE
elseif InStr(strUserAgent, "RV:11") then
IE = TRUE
IE11 = TRUE
end if
Opera = FALSE
Opera5 = FALSE
If InStr(strUserAgent, "Opera") or InStr(strUserAgent, "OPERA") or InStr(strUserAgent, "OPR") then
Opera = TRUE
end If
If InStr(strUserAgent, "Opera 5") _
or InStr(strUserAgent, "Opera/5") then
Opera5 = TRUE
end If
Firefox = FALSE
If InStr(strUserAgent, "Firefox") or InStr(strUserAgent, "FIREFOX") then
Firefox = TRUE
end If
Adroid = FALSE
If InStr(strUserAgent, "Mobile Safari") then
Adroid = TRUE
end If
Android = FALSE
If InStr(strUserAgent, "ANDROID") then
Android = TRUE
end If
Chrome = FALSE
If InStr(strUserAgent, "Chrome") then
Chrome = TRUE
end If
Safari = FALSE
If InStr(strUserAgent, "Safari") or InStr(strUserAgent, "SAFARI") then
Safari = TRUE
end If
If InStr(strUserAgent, "LINUX") > 0 or InStr(strUserAgent, "Linux") > 0 or InStr(strUserAgent, "IPHONE") > 0 or InStr(strUserAgent, "iPhone") > 0 or InStr(strUserAgent, "iPod") > 0 or InStr(strUserAgent, "iPad") > 0 or InStr(strUserAgent, "ANDROID") > 0 or InStr(strUserAgent, "Android") > 0 or InStr(strUserAgent, "Opera Mini") > 0 or InStr(strUserAgent, "SymbianOS") > 0 or InStr(strUserAgent, "Windows CE") > 0 or InStr(strUserAgent, "BlackBerry") > 0 or InStr(strUserAgent, "Nokia") > 0 or InStr(strUserAgent, "SonyEricsson") > 0 or InStr(strUserAgent, "webOS") > 0 or InStr(strUserAgent, "PalmOS") > 0 or InStr(strUserAgent, "Mobile Safari") > 0 then
mobile_check = 1
device2="mobile"
else
mobile_check = 0
device2="pc"
end if
if device="" then
device = device2
end if
if device = "pc" then
response.write "PC 입니다."
else
response.write "Mobile 입니다."
end if
%>
참고사이트
http://blog.naver.com/sm8569/100113041304
http://htglss.tistory.com/96
http://seroot.com/139
http://sir.kr/g5_tip/4467
브라우저 정보로 다른 내용 보이기
1. 자바스크립트로 제어하기
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
// 브라우저 정보로 홈페이지 이동하기
if( (navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/iPod/i)) ||
(navigator.userAgent.match(/Android/i)) ||
(navigator.userAgent.match(/Blackberry/i)) ||
(navigator.userAgent.match(/BB10/i)) ||
(navigator.userAgent.match(/OperaMobi/i)) ||
(navigator.userAgent.match(/Opera Mini/i)) ||
(navigator.userAgent.match(/IEMobile/i)) ||
(navigator.userAgent.match(/Jasmine/i)) ||
(navigator.userAgent.match(/Fennec/i)) ||
(navigator.userAgent.match(/Blazer/i)) ||
(navigator.userAgent.match(/Minimo/i)) ||
(navigator.userAgent.match(/MOT-/i)) ||
(navigator.userAgent.match(/Nokia/i)) ||
(navigator.userAgent.match(/SAMSUNG/i)) ||
(navigator.userAgent.match(/Polaris/i)) ||
(navigator.userAgent.match(/LG-/i)) ||
(navigator.userAgent.match(/SonyEricsson/i)) ||
(navigator.userAgent.match(/SIE-/i)) ||
(navigator.userAgent.match(/AUDIOVOX/i)) ||
(navigator.userAgent.match(/mobile/i)) ||
(navigator.userAgent.match(/webOS/i)) ) {
// 모바일 주소 표시줄 숨기기
window.addEventListener('load', function(){ setTimeout(scrollTo, 0, 0, 1); }, false);
// 모바일 버전으로 페이지 이동
document.location = "/mobile/";
}else{
// 웹 버전으로 페이지 이동
document.location = "/web/";
}
//-->
</script>
2. PHP 코드로 제어하기
2-1. < 사용예1 >
<?php
// 브라우저 정보로 홈페이지 이동하기
//preg_match 가 오류날때 즉, php 버전이 낮을 경우엔 eregi 를 써야 합니다.
if(preg_match('/(phone|samsung|lgtel|mobile|[^A]skt|nokia|blackberry|BB10|android|sony|SonyEricsson|DoCoMo|JVodafone|SoftBank|MOT-|UP.Browser|KDDI|WILLCOM|SHARP|DDIPOCKET|PSP|SymbianOS|Windows CE|webOS|PalmOS)/i', $_SERVER['HTTP_USER_AGENT']))
{
$URL= "http://m.happyjung.com/";
echo "<script type=\"text/javascript\">\n";
echo "<!--\n";
//echo "location.href = '". $URL."';\n"; // 현재창으로 전송
echo "parent.location.href='". $URL."';\n"; // 부모창으로 전송
echo "//-->\n";
echo "</script>\n";
exit;
}
$URL= "https://www.happyjung.com/";
echo "<script type=\"text/javascript\">\n";
echo "<!--\n";
//echo "location.href = '". $URL."';\n"; // 현재창으로 전송
echo "parent.location.href='". $URL ."';\n"; // 부모창으로 전송
echo "//-->\n";
echo "</script>\n";
?>
2-2. < 사용예2 >
<?php
// 브라우저 정보로 홈페이지 이동하기
if(preg_match('/(phone|samsung|lgtel|mobile|[^A]skt|nokia|blackberry|BB10|android|sony|SonyEricsson|DoCoMo|JVodafone|SoftBank|MOT-|UP.Browser|KDDI|WILLCOM|SHARP|DDIPOCKET|PSP|SymbianOS|Windows CE|webOS|PalmOS)/i', $_SERVER['HTTP_USER_AGENT']))
{ // 스마트폰 종류 확인
$hp_mobile_check="y";
}
?>
<?php if ($hp_mobile_check=="y") { ?>모바일일때<?php } ?>
3. ASP 코드로 제어하기
[ 방법.1 ]
<%
'Request.ServerVariables("HTTP_USER_AGENT") ' 접속자의 에이젼트 정보를 얻는함수
Dim arr_Browser, user_agent, i
arr_Browser = array("iPhone", "iPod", "IEMobile", "Mobile", "lgtelecom", "PPC", "BlackBerry", "BB10", "SCH-", "SPH-", "LG-", "CANU", "IM-" ,"EV-", "Nokia")
for i = 0 to Ubound(arr_Browser)
user_agent = arr_Browser(i)
If InStr(Request.ServerVariables("HTTP_USER_AGENT"), user_agent) = 0 then
response.redirect("http://m.happyjung.com/m/index.asp")
end if
next
%>
[ 방법.2 ]
<%
dim device, device2
dim strUserAgent ' 브라우저 타입
dim IE, IE6, IE7, IE8, IE9, IE10, IE11, Opera, Opera5, ChromeSafari, Chrome, Safari, Firefox, OtherBrowser
dim Adroid, Android
dim mobile_check
' 모바일인지, pc 인지 확인용
device=request("device")
'클라이언트 브라우저 환경 감지
strUserAgent = UCase(cstr(request.ServerVariables("HTTP_USER_AGENT")))
'response.write strUserAgent
IE = FALSE
IE6 = FALSE
IE7 = FALSE
IE8 = FALSE
IE9 = FALSE
IE10 = FALSE
IE11 = FALSE
if InStr(strUserAgent, "MSIE 6") then
IE = TRUE
IE6 = TRUE
elseif InStr(strUserAgent, "MSIE 7") then
IE = TRUE
IE7 = TRUE
elseif InStr(strUserAgent, "MSIE 8") then
IE = TRUE
IE8 = TRUE
elseif InStr(strUserAgent, "MSIE 9") then
IE = TRUE
IE9 = TRUE
elseif InStr(strUserAgent, "MSIE 10") then
IE = TRUE
IE10 = TRUE
elseif InStr(strUserAgent, "v:11") then
IE = TRUE
IE11 = TRUE
elseif InStr(strUserAgent, "RV:11") then
IE = TRUE
IE11 = TRUE
end if
Opera = FALSE
Opera5 = FALSE
If InStr(strUserAgent, "Opera") or InStr(strUserAgent, "OPERA") or InStr(strUserAgent, "OPR") then
Opera = TRUE
end If
If InStr(strUserAgent, "Opera 5") _
or InStr(strUserAgent, "Opera/5") then
Opera5 = TRUE
end If
Firefox = FALSE
If InStr(strUserAgent, "Firefox") or InStr(strUserAgent, "FIREFOX") then
Firefox = TRUE
end If
Adroid = FALSE
If InStr(strUserAgent, "Mobile Safari") then
Adroid = TRUE
end If
Android = FALSE
If InStr(strUserAgent, "ANDROID") then
Android = TRUE
end If
Chrome = FALSE
If InStr(strUserAgent, "Chrome") then
Chrome = TRUE
end If
Safari = FALSE
If InStr(strUserAgent, "Safari") or InStr(strUserAgent, "SAFARI") then
Safari = TRUE
end If
If InStr(strUserAgent, "LINUX") > 0 or InStr(strUserAgent, "Linux") > 0 or InStr(strUserAgent, "IPHONE") > 0 or InStr(strUserAgent, "iPhone") > 0 or InStr(strUserAgent, "iPod") > 0 or InStr(strUserAgent, "iPad") > 0 or InStr(strUserAgent, "ANDROID") > 0 or InStr(strUserAgent, "Android") > 0 or InStr(strUserAgent, "Opera Mini") > 0 or InStr(strUserAgent, "SymbianOS") > 0 or InStr(strUserAgent, "Windows CE") > 0 or InStr(strUserAgent, "BlackBerry") > 0 or InStr(strUserAgent, "Nokia") > 0 or InStr(strUserAgent, "SonyEricsson") > 0 or InStr(strUserAgent, "webOS") > 0 or InStr(strUserAgent, "PalmOS") > 0 or InStr(strUserAgent, "Mobile Safari") > 0 then
mobile_check = 1
device2="mobile"
else
mobile_check = 0
device2="pc"
end if
if device="" then
device = device2
end if
if device = "pc" then
response.write "PC 입니다."
else
response.write "Mobile 입니다."
end if
%>
참고사이트
http://blog.naver.com/sm8569/100113041304
http://htglss.tistory.com/96
http://seroot.com/139
http://sir.kr/g5_tip/4467
댓글목록
등록된 댓글이 없습니다.