Home >Backend Development >PHP Tutorial >How to use php to obtain the client computer screen parameters
This article mainly introduces the method of php to obtain the parameters of the client computer screen. It can obtain width, height, resolution and other parameters. It mainly uses the js method to obtain the parameters of the client computer screen and then uses Ajax to return to the server. , and then realize the function of obtaining the client computer screen parameters. Friends in need can refer to the following
This article describes the method of obtaining the client computer screen parameters in PHP. Share it with everyone for your reference. The specific analysis is as follows:
The first thing to note is that php is a server-side language and cannot obtain the width and height of the client's screen. However, a workaround is to obtain the width and height of the client's computer screen through the client script language javascript, and then pass it to the php script language in the form of ajax or cookie, thereby implementing php How to get the client computer screen width and height.
The method of obtaining the width, height, and resolution of the client computer through javascript is as follows:
The height of the screen resolution: window.screen.height
Width of screen resolution: window.screen.width
Screen available work area height: window.screen.availHeight
Screen available work area width: window. screen.availWidth
The method passed to the php server is as follows:
The code is as follows:
$.post('http://localhost/php/index.php',{w:width,h:height});//这里忽略了返回值
Based on the above, the width and height of the client computer display screen are obtained through php , the complete code of the resolution is as follows:
The code is as follows:
<html"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript"> $(function(){ var width=window.screen.height; var height=window.screen.width; $.post('http://localhost/php/index.php',{w:width,h:height});//这里向你的统计文件里面传入相关的参数 }); </script> </head> <body> 这里是正文...... </body> </html>
The above is the detailed content of How to use php to obtain the client computer screen parameters. For more information, please follow other related articles on the PHP Chinese website!