How to detect screen resolution

PHP does not provide native function that can detect the device display resolution. Java Script can be used in this case, which will detect the display resolution. The script will do so, by using the width and height features of the screen. The required code for this has to be inserted into a HTML document. Once it is done, the settings can be switched to the PHP script through proper coding methods.

This will be the codes that you can use to make your website pages look better in all devices.

<script language="Javascript">
if(screen.width < 500)
// this space will look good on cellphone < 500px wide
document.write('<p><img src="images/pixel_trans.gif" height="430"></p>');
</script>

Based on this resolution detector, you can redirect users to a different domain name such as mobile.YOUR-DOMAIN.com or m.YOUR-DOMAIN.com or apply a different stylesheet .css.