Getting Screen resolution using JavaScripts & PHP
Overview: In this article we will discuss how to get the users screen resolution.
Wouldnít it be great if you get the users screen resolution so that you could send optimized content for that particluar resolution, we can get users resolution using JavaScriptís but the problem is how do we get PHP to recognize it.
What we can do is get the users resolution using JavaScript and then set a cookie which has the users resolution, we can then access that cookie in PHP!
How can I get the users screen resoultion using JavaScript?
It's really simple I will show you the code
screen.width; //gives you the screen width
screen.height; //gives you the screen height
I will explain you the stuff with an example We will be using get_resolution.php with the help of JavaScript we will get the screen resolution and then set the screen resolution's value in a cookie named users_resolution when ever we execute the page we check with PHP to see if the cookie users_resolution is set, if it is not set we set it using JavaScript.
if(isset($HTTP_COOKIE_VARS["users_resolution"]))
$screen_res = $HTTP_COOKIE_VARS["users_resolution"];
else //means cookie is not found set it using Javascript
{
?>
}
?>
|
Editor: PHPbuddy also uses the same kind of code to send optimized content for different resolutions if you are at 800*600 or lower resolution set your resolution to 1024*768 and check PHPbuddy! (Be sure to reload the site after you change your resolution) |
|
Home | Privacy Policy | Contact Us | Terms of Service
(c) 2002 - 2018 www.PHPbuddy.com Unauthorized reproduction/replication of any part of this site is prohibited.
|