Live Brilliant

HTTP_USER_AGENT 모바일 접속 구분 본문

개발은 핵찜이야/mobile web

HTTP_USER_AGENT 모바일 접속 구분

주인정 2012. 7. 4. 17:11

#모바일웹 에이전트 체크

# HTTP_USER_AGENT 사용하여 모바일 감지

[php]

$mobile = false;

if(isset($_SERVER['HTTP_USER_AGENT']))

{

    $mobile_agents = '!(tablet|pad|mobile|phone|symbian|android|ipod|ios|blackberry|webos)!i';

    if(preg_match($mobile_agents, $_SERVER['HTTP_USER_AGENT']))

    {

       $mobile = true;

    }

}


[압축하여 코딩]

isset($_SERVER['HTTP_USER_AGENT']) && preg_match('!(tablet|pad|mobile|phone|symbian|android|ipod|ios|blackberry|webos)!i', $_SERVER['HTTP_USER_AGENT']) ? $mobile = true : $mobile = false;


[script]

        <script language="Javascript">

function ismobile(){

var mobileKeyWords = new Array('iPhone', 'iPod', 'BlackBerry', 'Android', 'Windows CE', 'LG', 'MOT', 'SAMSUNG', 'SonyEricsson');

   for (var word in mobileKeyWords){

    if (navigator.userAgent.match(mobileKeyWords[word]) != null){

document.body.style.zoom = "250%";

}

   }

}

        </script>

<body onload="ismobile();">



[ASP]


If authAdminID = "" Then

Dim arr_Browser 

arr_Browser =  array("iPhone", "iPod", "IEMobile", "Mobile", "lgtelecom", "PPC", "BlackBerry", "SCH-", "SPH-", "LG-", "CANU", "IM-" ,"EV-","Nokia")

for i = 0 to Ubound(arr_Browser)

Dim user_agent : user_agent = arr_Browser(i)

  If InStr(Request.ServerVariables("HTTP_USER_AGENT"), user_agent) >= 1 then

     response.redirect("m.login.asp")

   end if

next

End IF

Comments