Wallpapers Forums Login

How To Get Screen Resolution Show Screen Size Script With Php Javascript Sample Demo

if you want to get your visitor's or users screen resolution. sometimes it helps to know about your users to customize software applications to make their expirience more enjoyable. with wallpapers, getting the user's screen resolution is very important in determining the needs of your visitors.

UPDATE:
a new version of this script is available at the following post:
How To Get Screen Resolution


well, with php, you can get and show the screen resolution by using javascript.

the javascript code:
lt;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 = 'test.php';
}
//-->
</script>


the code:
<?php
if(isset($HTTP_COOKIE_VARS["users_resolution"]))
$screen_res = $HTTP_COOKIE_VARS["users_resolution"];


if you want to put it all together, i have created a complete hmtl demo. all you have to do is copy and paste code below into notepade, then save it as wallpaperama.php and upload to your php website, then open it with your browser and it will show you what YOUR screen resolution is.

The Complete Page
<HTML>
<TITLE>Show Screen Resolution</TITLE>
<HEAD>
<?php
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 = 'wallpaperama.php';
}
//-->
</script>
<?
}
?>
</HEAD>
<BODY>
<h1>Screen Resolution by Wallpaperama.com </h1><hr>
<p>This script will show you what your screen resolution is set to using php and javascript.</p>
<p style="color:#FF0000"><?php
echo "Your Screen resolution is set at ". $screen_res;
?>
</p>
<p>If you found this script helpful, we would appreciate a link to wallpaperama.com ? Why link to us. by linking to wallpaperama.com you will help others find this free script and others in our library. </p>
<p>Thanks</p>
<p>Wallpaperama Team</p>
<p align="center">PHP Hosting Provided By <a href="http://www.webune.com">Webune.com</a> </p>
</BODY>
</HTML>
rajesh Sun Apr 15, 2012
good info...but could anyone plz help me to get this code in coldfusion 7....? thanks
Gayathiri Mon Jan 09, 2012
Hi.. Thanx a lot.. Code is working fine.. But am facing a small issue.. Am not getting the resolution values, when the page is loaded for the first time or when i clear the browser cookie.
Can anyone pl help me out to solve this..
Wallpaper Thu May 05, 2011
This is really helpful to me as i was looking for the same resolution from last week.
mr_scp Tue Jan 18, 2011
thanx thanx thanx
vishal Mon Sep 13, 2010
Thank you so much..

This logic help me most...

Thanks...Thanks.
FeralReason Wed Jun 09, 2010
Works fine in a localhost environment but when I copy it to my web server, it produces the cookie but it doesn't read the cookie. Any ideas ?
Craig Sun May 09, 2010
This code solved a problem I spent a long time working on. Thanks! I am in the midst of a major overhaul, but I will include a link to your site.
Amit Wed Mar 17, 2010
Hello ,

script is not working :(
Thanks
Amit
ozyrys Mon May 18, 2009
it works fine on simple page. but when i pasted this code to drupal cms template, page is still reloading. it looks like cookie is not set. please help!
anon Tue Jan 20, 2009
you steal this stuff from phpbuddy
wow, great
Lucie Tue Apr 29, 2008
great code, it worked fine, thank you
guides Mon May 21, 2007
thanks, this is a good how to find screen resolution using php tutorial guide.

Related Content

Information

Share

wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5