[PHP]Detect the display resolution

Last update on December 21, 2008 08:48 AM by jak58
Published by jak58

[PHP]Detect the display resolution







PHP does not possess any function allowing detection of the display resolution.

The solution is to make use of Javascript to detect the resolution through the width and height attributes of the screen:

screen.width 
screen.height 


Thus the following code, once inserted into an HTML document:
<script language="Javascript">
<!--
document.write('<br>your resolution is'.screen.width+'x'+screen.height)
//-->
</script>
 


It is possible to switch the setting to a PHP script via Javascript.

<?
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
     }
}

?>
Best answers for « Detect the display resolution » in :
Displaying video from a PC on a television screen Show Displaying video from a PC on a television screen TV output S-Video output Configuration under Windows FAQ You can display the output from the computer on a television (or even the sound on an amplifier). But that implies that the...
Adjusting your websites to fit all types of resolution ShowAdjusting your websites to fit all types of resolution "How to adjust my site to the visitor's resolution and what resolution to choose?" Simply apply a relative width (= that changes with the size of the window and screen of the...
How to detect your public IP address? ShowHow to detect your public IP address? The ipconfig for Windows also known as ifconfig under Linux display your IP address. However behind a router that makes NAT, this will not surely correspond to your public IP address which however...
Windows Update – Detection Frequency Configuration ShowWindows Update – Detection Frequency Configuration By the registry On the Control Panel Vista XP You can change the Update detection frequency on windows because windows does automatically searches for updates! By the registry Save...
Download Driver Detective ShowDescription Driver Detectiveis an application designed by Drivers Headquarters, Inc. This application will allow you between others to prove every time if you have last updates for the drivers of your equipments. Advantage The application...
Computer screen or monitor ShowIntroduction to computer monitors A monitor (or screen) is a computer display unit. There are generally said to be two families of monitors: Cathode-ray tube monitors (or CRT for short), which are used with most desktop computers. They are...
Intrusion detection systems (IDS) ShowIntroduction to intrusion detection systems An IDS (Intrusion Detection System) is the term for a mechanism which quietly listens to network traffic in order to detect abnormal or suspicious activity, thereby reducing the risk of intrusion. There...
Attack detection ShowAnalysing logs One of the best ways to detect intrusions is to monitor event logs (sometimes called logs for short). In general, servers store logs of their activity, and in particular any errors encountered, in files. Therefore, after a computer...