Page 1 of 1

Determining screen resolution

Posted: Wed Dec 01, 2010 5:53 am
by Callan S.
I found some code that says it will use javascript to return the resolution the user has, yet it has an odd error that I can't figure out.

Code: Select all

<?
if(!isset($_GET['r']))
{
echo "<script language=\"JavaScript\">
<!--
document.location=\"$PHP_SELF?r=1&width=\"+screen.width+\"&Height=\"+screen.height;
//-->
</script>";
}
else {   

// Code to be displayed if resolutoin is detected
     if(isset($_GET['width']) && isset($_GET['Height'])) {
               // Resolution  detected
     }
     else {
               // Resolution not detected
     }
}

?>
Yet in wamp it outputs this, for some reason echoing everything after the script ends.

Code: Select all

; } else { // Code to be displayed if resolutoin is detected if(isset($_GET['width']) && isset($_GET['Height'])) { // Resolution detected } else { // Resolution not detected } } ?>

Re: Determining screen resolution

Posted: Wed Dec 01, 2010 6:28 am
by kaos78414
I found this solution which is a little cleaner, maybe it'll work for ya.

Code: Select all

<script language="javascript">
if (window.location.search == "") {
window.location.href = window.location + "?width=" + screen.width + "&height=" + screen.height;
}
</script>

Code: Select all

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

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

Re: Determining screen resolution

Posted: Wed Dec 01, 2010 7:17 am
by Callan S.
Nice one, Kaos, thanks!