Detecting Smart Phone Screen Orientation in PHP & Javascript
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 :
Twitter:
- Any AS3 developers looking for a full-time job out in Chiswick, London? Our agency (@candyspacemedia) have an opening for an AS3 / Air Dev… 7 hrs ago
- Flash Platform Roadmap : http://t.co/0JtJnamP looks promising, especially "Dolores" threading in AS3! 14 hrs ago
- @FDT5 Cheers :) in reply to FDT5 3 weeks ago
- More updates...
Posting tweet...
Friends






