본문 바로가기

개발도구/PHP,ASP,JSP,SCRIPT

[php] 스마트 폰 가로지원 환경설정 - Detecting Smart Phone Screen Orientation in PHP & Javascript

<?php
if( isset($_COOKIE['orientation']) ){
    $rotation = $_COOKIE['orientation'];
    if( $rotation == 0 ){
        echo '<h1>Is Portrait</h1>';
    }else{
        echo '<h1>Is Landscape</h1>';
    }
 }else{
?>
    <script type="text/javascript" language="javascript">
        function writeCookie(){
            the_cookie = document.cookie;
            var orientation = 0;
            if( window.orientation ){
                orientation = window.orientation;
            }
            the_cookie = 'orientation='+window.orientation+';'+the_cookie;
            document.cookie = the_cookie;
            document.location = '<?=$_SERVER['PHP_SELF']?>';
        }
        document.body.addEventListener('orientationchange', writeCookie );
        writeCookie();
    </script>
<?php
    }
?>