Introduction
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!
Using the Code
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.
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'];
Notice!
For first load, client resolution data is not accessible with PHP, because JavaScript should set this data in cookies.
I'm a persian software maker/developer & user interface designer.
I like creativity & open-source.
My dream language is javascript, i like to make & develop online applications!
My believe in web like real world, and i love it, I'm trying for design with art.
Coding for me is enjoyable & can't make me tired.