by Hiroshi on August 7th, 2008

I think there is no way yet to find out screen resolution with PHP. hehehe.
If I am wrong please correct me.
But yet we can trick it to be happen ;-)
If not then how can we be developers. Right!

With javascript we find out screen resolution of PC. Store it in a cookie and display it with PHP.
Coool…eh! Fine, lets just do it.

<script LANGUAGE="javascript">
width = screen.width;
height = screen.height;
document.write("<b>You're set to "+width+ "X" +height+"</b>")
</script>
<?php
$yo=$_GET['width'];
echo $yo;
?>

For head section of webpage.

<?
if(isset($HTTP_COOKIE_VARS["users_resolution"]))
$screen_res = $HTTP_COOKIE_VARS["users_resolution"];
else //means cookie is not found set it using Javascript
{
?>
<script language="javascript">
<!--
writeCookie();
function writeCookie()
{
var today = new Date();
var the_date = new Date("December 31, 2023");
var the_cookie_date = the_date.toGMTString();
var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
document.cookie=the_cookie
location = 'screen.php';
}
//-->
</script>
<?
}
?>

Body section of webpage. Display the screen resolution.

<?php
echo "Your screen resolution is set at ". $screen_res;
?>

Enjoy!!! …Chill Pill…

Download Script

  • Share/Bookmark

, , , ,

3 Reviews

  1. Rkey says:

    Well, this approach a bit complicated.
    Here is a much simpler hack:

    $sw = “document.write(screen.width)”;
    $sh = “document.write(screen.height)”;
    print $sw;
    print $sh;

  2. Th4n4t0s says:

    <?
    $sw = "document.write(screen.width)”;
    $sh = “document.write(screen.height)”;
    print $sw;
    print $sh;
    ?>

    You can use this on works for me =)

Leave a Review

Incoming Searches

php screen resolution, php get screen resolution, php resolution, php screen width, get screen resolution php, screen resolution php, detect screen resolution php, php get screen width, php screen size, php get browser width, screen resolution in php, php browser resolution, php browser width, php get screen size, screen width php, php determine screen size, browser resolution php, php script resolution, write screen resolution to mysql, php screen resoultion, php screen resolution script, php resolution detection, php print screen width, php to check for screen size, php to identify screen resolution, write screen resolution php, wordpress variables detect resolution, wordpress theme risolution browser, wordpress detect screen resolution and adjust theme to match, screen width in php, screen width in image width, screen width get php cookie, screen width and height with php, screen resolution with php, screen resolution using php, screen resolution by php, resolution PHP, resolution in php, php to identify user’s screen resolution, php how to get screen resolutionç, php how to find screen resolution, php , monitor screen Resolution php, image width height resolution php, how to know screen resolution in php, how to get screen resolution in php, how to add image in php of screen width, heldesk resolution script, get resulution php, get resolution php, get document height with php, find video resolution by php, browser screen resolution php, browser resolution get php, php browser width height resolution, php change screen resolution, php get user resolution, php get screen width without javascript, php get screen width image, php find screen resolution, php get resolution browser, php get resolution, php get browser resolution, php function screen resolution, php detect screen size, php detect screen resolution, php detect resolution, php detect browser resolution, php check screen resolution, $HTTP_COOKIE_VARS[users_resolution]