Jump to content

[SOLVED] get screen resolution.. is it possible with php?


Recommended Posts

You cannot use php alone to get it because it's a server-side language. What you CAN do is use javascript (which is a client-side language) and write a cookie to the users machine that your php can then read.

 

Check out this link:

http://www.phpbuddy.com/article.php?id=8

 

You can see it working here:

http://www.phpbuddy.com/sample/get_resolution.php

thanks,

I'd already found that article, but it doesn't seem to work.

If I go to the page to see it it just seems to do nothing. It just has the page loading bar, but I think it might be in a continuos loop of refreshing the page...

 

I tried copying the code onto my own server and I get the same thing :-\

Sounds like a browser setting.

 

At anyrate that code is soooo out dated, try this updated version

 

<HTML>
<TITLE>PHPBuddy getting screen resolution</TITLE>
<!--
(c) http://www.phpbuddy.com (Feel free to use this script but keep this message intact)
Author: Ranjit Kumar (Cheif Editor phpbuddy.com)

UPDATED: by Frost110
-->
<HEAD>
<?php
$screen_res = "";
if(isset($_COOKIE["users_resolution"]))
$screen_res = $_COOKIE["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 = 'get_resolution.php';
}
//-->
</script>
<?php
}
?>
</HEAD>
<BODY>
<?php
echo "Your Screen resolution is set at ". $screen_res;
?>
</BODY>
</HTML>

 

Just changed a few items, see if that works or not.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.