DaveC asked the question about orientation

So I thought I’d drop a quick note on the code :

<?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
	}
?>

Some examples of this code working :

Tagged with:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>