Use PHP to obtain client resolution data

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.