Dragen Posted June 15, 2007 Share Posted June 15, 2007 Okay, Is there a way that I can get the users screen resolution using php? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/55742-solved-get-screen-resolution-is-it-possible-with-php/ Share on other sites More sharing options...
atomicrabbit Posted June 15, 2007 Share Posted June 15, 2007 You cannot use php alone to get it because it's a server-side language. What you CAN do is use javascript (which is a client-side language) and write a cookie to the users machine that your php can then read. Check out this link: http://www.phpbuddy.com/article.php?id=8 You can see it working here: http://www.phpbuddy.com/sample/get_resolution.php Quote Link to comment https://forums.phpfreaks.com/topic/55742-solved-get-screen-resolution-is-it-possible-with-php/#findComment-275406 Share on other sites More sharing options...
Dragen Posted June 15, 2007 Author Share Posted June 15, 2007 thanks, I'd already found that article, but it doesn't seem to work. If I go to the page to see it it just seems to do nothing. It just has the page loading bar, but I think it might be in a continuos loop of refreshing the page... I tried copying the code onto my own server and I get the same thing :-\ Quote Link to comment https://forums.phpfreaks.com/topic/55742-solved-get-screen-resolution-is-it-possible-with-php/#findComment-275424 Share on other sites More sharing options...
atomicrabbit Posted June 15, 2007 Share Posted June 15, 2007 it worked when i visited the page.. are javascript and cookies enabled on your browser? Quote Link to comment https://forums.phpfreaks.com/topic/55742-solved-get-screen-resolution-is-it-possible-with-php/#findComment-275433 Share on other sites More sharing options...
Dragen Posted June 15, 2007 Author Share Posted June 15, 2007 yes. I don't understand why it didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/55742-solved-get-screen-resolution-is-it-possible-with-php/#findComment-275441 Share on other sites More sharing options...
per1os Posted June 15, 2007 Share Posted June 15, 2007 Sounds like a browser setting. At anyrate that code is soooo out dated, try this updated version <HTML> <TITLE>PHPBuddy getting screen resolution</TITLE> <!-- (c) http://www.phpbuddy.com (Feel free to use this script but keep this message intact) Author: Ranjit Kumar (Cheif Editor phpbuddy.com) UPDATED: by Frost110 --> <HEAD> <?php $screen_res = ""; if(isset($_COOKIE["users_resolution"])) $screen_res = $_COOKIE["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> <?php } ?> </HEAD> <BODY> <?php echo "Your Screen resolution is set at ". $screen_res; ?> </BODY> </HTML> Just changed a few items, see if that works or not. Quote Link to comment https://forums.phpfreaks.com/topic/55742-solved-get-screen-resolution-is-it-possible-with-php/#findComment-275458 Share on other sites More sharing options...
Dragen Posted June 15, 2007 Author Share Posted June 15, 2007 thanks frost! worked great first time! Quote Link to comment https://forums.phpfreaks.com/topic/55742-solved-get-screen-resolution-is-it-possible-with-php/#findComment-275463 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.