Hendo Posted April 11, 2008 Share Posted April 11, 2008 Hi, I'm currently developing a website, where I've been setting the layout to fit perfectly for my screen resolution, only to be stupid enough to realise that the layout would be messed up on a smaller screen. Is there a way to use PHP to check the screen resolution, then set the layout accordingly? I know this is a big ask, and I don't think the answer will be yes, but thats the only idea I've got to sort this issue out! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/100658-screen-resolution-checking-with-php/ Share on other sites More sharing options...
laffin Posted April 11, 2008 Share Posted April 11, 2008 U will need Javascript as screen resolution, as screen resolution is not passed between browser and server. found this link that may help Getting Screen resolution using JavaScripts & PHP Quote Link to comment https://forums.phpfreaks.com/topic/100658-screen-resolution-checking-with-php/#findComment-514800 Share on other sites More sharing options...
PFMaBiSmAd Posted April 11, 2008 Share Posted April 11, 2008 The code at that link is really old and won't work on most current php installations. There is a simpler way and it uses less code - http://www.php.net/manual/en/faq.html.php#faq.html.javascript-variable Quote Link to comment https://forums.phpfreaks.com/topic/100658-screen-resolution-checking-with-php/#findComment-514840 Share on other sites More sharing options...
Hendo Posted April 12, 2008 Author Share Posted April 12, 2008 That works great, except how would use it in conjunction with a javascript if statement? Here is what I have at the moment, I added the if statement at the end <?php if (isset($_GET['width']) AND isset($_GET['height'])) { // output the geometry variables echo "Screen width is: ". $_GET['width'] ."<br />\n"; echo "Screen height is: ". $_GET['height'] ."<br />\n"; } else { // pass the geometry variables // (preserve the original query string // -- post variables will need to handled differently) echo "<script language='javascript'>\n"; echo " location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}" . "&width=\" + screen.width + \"&height=\" + screen.height;\n"; echo "if(screen.width==1280)\n"; echo "{\n"; echo "document.write('Hello');\n"; echo "}\n"; echo "</script>\n"; exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/100658-screen-resolution-checking-with-php/#findComment-515708 Share on other sites More sharing options...
Hendo Posted April 22, 2008 Author Share Posted April 22, 2008 Could someone help me with the above code? Quote Link to comment https://forums.phpfreaks.com/topic/100658-screen-resolution-checking-with-php/#findComment-524049 Share on other sites More sharing options...
laffin Posted April 26, 2008 Share Posted April 26, 2008 The php if statement bypasses the javascript if statement. notice that the javascript redirects the user to your script if a hieght width isn't sent. PHP Logic Do we have height width parameters Yes, Display some Info No, Use Javascript to detect parameters and reload page with parameters Quote Link to comment https://forums.phpfreaks.com/topic/100658-screen-resolution-checking-with-php/#findComment-527776 Share on other sites More sharing options...
Hendo Posted April 27, 2008 Author Share Posted April 27, 2008 So what would I use if I wanted to use the PHP "include" statement? Would I do it via PHP or javascript? Quote Link to comment https://forums.phpfreaks.com/topic/100658-screen-resolution-checking-with-php/#findComment-528382 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.