Jump to content

Check Screen Resoultion in PHP


johnsmith153

Recommended Posts

I am checking on my site a users screen resolution and directing them to a version of the site depending on it.

 

Can any of this be done with PHP as opposed to javascript?

 

I know certain tests need the browser, i.e checking if javascript on/off - but surely screen res is about the monitor, not the browser.

 

Others have said it cant be done in PHP, but you PHP freaks I am sure will prove otherwise.

Link to comment
https://forums.phpfreaks.com/topic/104728-check-screen-resoultion-in-php/
Share on other sites

i found this on the net.

<?
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 = 'get_resolution.php';
}
//-->
</script>
<?
}
?> 

 

or this

 Put this on the page:

<script language="javascript">
window.location.href = "screen.php?width=" + screen.width + "&height=" + screen.height;
</script>

Then create a file called screen.php and use this:

<?php
$width = $_GET['width'];
$height = $_GET['height'];

echo "You are using a $width x $height screen resolution";
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.