Jump to content

Screen resolution

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guests
How do I get the screen resolution using PHP?

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
The screen resolution of the server or the client?
To get the resolution of the server you would have to use the exec() function and execute the unix/dos command to get the resolution (are there any?)

But you probably mean the client, which you would use JavaScript

<script type="text/javascript"> 

  document.write(window.screen.width + ' x ' + window.screen.height); 

</script> 

You can write the resolution to a cookie and use the php cookie functions to grab the resolution from the cookie file.

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
To get the client records you will need to use Javascript and there is no way that PHP can receive this value since it is server side.

#4
Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guests
Hmm, I really just need to make an if statement and if their resolution is lower than a certain value display an error message. Do I need to do a cookie and everything for that?

#5
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
How would you compare the value?
if(<script type="text/javascript"> 
  document.write(window.screen.width + ' x ' + window.screen.height); 
</script> < 1024)
echo "Error";

Im pretty sure if you want to use php to display the error message you have to use cookies, unless there is another way to store the width/height. You could always of course display the error in JavaScript. Im no JS expert but maybe something like this

<script type="text/javascript">
if(window.screen.width < 1024)
allert("Your screen is too small");
</script>


#6
Guest_Jordan_*

Guest_Jordan_*
  • Guests
What Sidewinder suggested would work well. You could also create a dynamic page using JavaScript or simply forward the user to an error page (like res.html) with the same logic above.

#7
Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guests
That works. I'll figure out something. Thank you.