For the life of me it is not working and I tested it all different ways and then realised that the $height variable is not a number and therefore was the comparison was not working.
You can’t. AT first PHP runs on the server and after that JavaScript runs on the client. There is no way to get a direct interaction between the two.
<?php
if(!isset($_GET['screen_check']))
{
/* This code will be executed if screen resolution has not been detected.*/
echo "<script language='JavaScript'>
<!--
document.location=\"$PHP_SELF?screen_check=done&Width=\"+screen.width+\"&Height=\"+screen.height;
//-->
</script>";
}
else
{
/* This code will be executed after screen resolution is detected.*/
if(isset($_GET['Width']) && isset($_GET['Height'])) {
// Resolution detected
//echo "<h1>Your screen resolution is ".$_GET['Width']." x ".$_GET['Height'].".</h1><br />";
//Display page as per resolution
if(($_GET['Height']>665)) {
//echo "<b>This will be displayed when screen resolution is greater than 1024x768.</b>";
}
else {
//Display page as per resolution
//echo "<b>This will be displayed when screen resolution is either equal to or less than 1024x768.</b>";
}
}
else {
// Resolution not detected
}
}
?>
if ("<script>document.write(screen.height); </script>" < 665) { }
or as PHP sees it:-
if ("Some random string of whatever" < 665) { }
Which will always be true.
To PHP that is just a string, it does not run javascript. The browser runs javascript, after PHP has finished doing its job on the server.
Exactly what I was going to suggest.
Except using a min-height query rather than width.