웹개발/PHP

mobile check

광박이 2011. 2. 11. 12:25
728x90

<?php
function mobile_check() {
    $arr_browser = array ("iphone","android", "ipod","iemobile","mobile","lgtelecom","ppc", "symbianos","blackberry");
    $httpUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']);

    # 기본값으로 모바일 브라우저가 아닌것으로 간주함
    $mobile_browser = false;

    # 모바일브라우저에 해당하는 문자열이 있는 경우 $mobile_browser 를 true로 설정
    for ($indexi = 0 ; $indexi < count($arr_browser) ; $indexi++) {
        if (strpos($httpUserAgent, $arr_browser[$indexi]) == true) {
            $mobile_browser = true;
            break;
        }
    }

    # 모바일 브라우저인 경우 아래 주소로 이동
    if ($mobile_browser) {
        $changeURL = PATH.'mobile/';
        header("Location:".$changeURL);
        exit;
    }
}
?>

728x90