In PHP, client resolution data is not accessible directly, but in JavaScript, screen width & height is accessible directly! In these two languages, we can set and get cookies, so, we can set resolution data in a cookie with JavaScript and receive it with PHP!
Ok, now we should get client resolution data with JavaScript. For getting this data in all browsers, we should define a cross-browser code to get screen width and height.
width
height
if(typeof(window.innerWidth) !== 'number') { if(document.documentElement.clientWidth !== 0) { width = document.documentElement.clientWidth; height = document.documentElement.clinetHeight; } else { width = document.body.clientWidth; height = document.body.clinetHeight; } } else { width = window.innerWidth; height = window.innerHeight; }
Width & height variables are client resolution data.
We should set two cookies, width and height:
document.cookie = 'width' + '=' + width; document.cookie = 'height' + '=' + height;
Now, this data is stored in cookies and we can access these cookies with PHP.
For example:
echo $_COOKIE['width'];
For first load, client resolution data is not accessible with PHP, because JavaScript should set this data in cookies.