For the first load, the client-side resolution data is not accessed using PHP, because JavaScript should set this data in cookies
Introduction
In PHP, the client-side resolution data is not directly accessed, but in JavaScript, the screen width and height are directly accessed! In these two languages, we can set cookies, so we can set resolution data to use JavaScript in cookies and receive data with PHP!
Code of use
Now we should use JavaScript client-side resolution data. To get this data in all browsers, we should define a cross-browser code to get the screen width and height.
If (typeof (window. innerWidth )! = 'Number '){
If(document.doc umentElement. clientWidth! = 0 ){
Width = document.doc umentElement. clientWidth;
Height = document.doc umentElement. clinetHeight;
}
Else {
Width = document. body. clientWidth;
Height = document. body. clinetHeight;
}
}
Else {
Width = window. innerWidth;
Height = window. innerHeight;
}
The width and height variables are the data at the client resolution.
We should set two cookies, width and height:
Document. cookie = 'width' + '=' + width;
Document. cookie = 'height' + '=' + height
Now, this data is stored in cookies. we can use PHP to access these cookies.
For example:
Echo $ _ COOKIE ['width'];
Note!
For the first load, the client-side resolution data is not accessed using PHP, because JavaScript should set this data in cookies