johnsmith153 Posted May 8, 2008 Share Posted May 8, 2008 I am checking on my site a users screen resolution and directing them to a version of the site depending on it. Can any of this be done with PHP as opposed to javascript? I know certain tests need the browser, i.e checking if javascript on/off - but surely screen res is about the monitor, not the browser. Others have said it cant be done in PHP, but you PHP freaks I am sure will prove otherwise. Quote Link to comment https://forums.phpfreaks.com/topic/104728-check-screen-resoultion-in-php/ Share on other sites More sharing options...
DeanWhitehouse Posted May 8, 2008 Share Posted May 8, 2008 i found this on the net. <? if(isset($HTTP_COOKIE_VARS["users_resolution"])) $screen_res = $HTTP_COOKIE_VARS["users_resolution"]; else //means cookie is not found set it using Javascript { ?> <script language="javascript"> <!-- writeCookie(); function writeCookie() { var today = new Date(); var the_date = new Date("December 31, 2023"); var the_cookie_date = the_date.toGMTString(); var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height; var the_cookie = the_cookie + ";expires=" + the_cookie_date; document.cookie=the_cookie location = 'get_resolution.php'; } //--> </script> <? } ?> or this Put this on the page: <script language="javascript"> window.location.href = "screen.php?width=" + screen.width + "&height=" + screen.height; </script> Then create a file called screen.php and use this: <?php $width = $_GET['width']; $height = $_GET['height']; echo "You are using a $width x $height screen resolution"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/104728-check-screen-resoultion-in-php/#findComment-536060 Share on other sites More sharing options...
RichardRotterdam Posted May 8, 2008 Share Posted May 8, 2008 you will always need javascript for that since php runs on the server and doesnt know a thing about your computer settings Quote Link to comment https://forums.phpfreaks.com/topic/104728-check-screen-resoultion-in-php/#findComment-536062 Share on other sites More sharing options...
PFMaBiSmAd Posted May 8, 2008 Share Posted May 8, 2008 Here is one self contained piece of javascript/php that does this - http://www.php.net/manual/en/faq.html.php#faq.html.javascript-variable Quote Link to comment https://forums.phpfreaks.com/topic/104728-check-screen-resoultion-in-php/#findComment-536069 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.