Jump to content

Screen resolution checking with PHP


Hendo

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/100658-screen-resolution-checking-with-php/
Share on other sites

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();
}
?> 

  • 2 weeks later...

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.