Find Screen Resolution With PHP
by Hiroshi on August 7th, 2008
sponsored links
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…
sponsored links



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;
@Rkey: Thanks RKey.
<?
$sw = "document.write(screen.width)”;
$sh = “document.write(screen.height)”;
print $sw;
print $sh;
?>
You can use this on works for me =)
___________
That isn’t getting the width or height with PHP, that is printing JS commands that get the width and height. There’s a big difference.
In php code, you can use this.
<?php
$sw = 'document.write(screen.width)’;
echo ‘your screen resolution is: ‘.$sw;
?>