Jump to content

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.