How to use php to obtain the client computer screen parameters

怪我咯
Release: 2023-03-12 17:24:01
Original
1544 people have browsed it

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});//这里忽略了返回值
Copy after login

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(&#39;http://localhost/php/index.php&#39;,{w:width,h:height});//这里向你的统计文件里面传入相关的参数
});
</script>
</head>
<body>
这里是正文......
</body>
</html>
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!