php可以检测客户端浏览器显示器的大小/分辨率吗?
PHP可以检测IP、主机名、客户端代理等。PHP可以检测客户端浏览器监视器的大小/分辨率吗?
Php can detect IP, hostname, client agent etc. Can php detect client browser monitor size/resolution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
不,不能。 PHP 在服务器上运行,因此它无法检测客户端设置,除非您采取特定的客户端步骤将信息传递到服务器上的 PHP 脚本。
No, it cant. PHP runs on the server, so it cant detect client settings unless you take specific client-side steps to pass the info to the PHP scripts on the server.
请注意,我们中的一些人喜欢我们的浏览器不最大化。 也许您最好尝试检测浏览器大小而不是屏幕分辨率。 我认为执行任一操作的 JS 都非常相似,但我实际上并不知道情况是这样。
另外,盲人屏幕阅读器的分辨率是多少?
Please do note that some of us like our browsers non-maximized. Perhaps you'd be better off trying to detect browser size rather than screen resolution. I assume that the JS to do either would be very similar, but I don't actually know that to be the case.
Also, what is the resolution of a blind man's screen reader?
您必须将 PHP 与 JavaScript 一起使用,例如 这个例子:
You'll have to use PHP together with JavaScript, like in this example:
我也在寻找这个,但发现这些答案都没有真正回答问题! 事实上,PHP 无法知道屏幕分辨率,因为它运行在服务器端。 由于该信息未在 HTTP 环境变量中传递,因此我们需要另一个路由。 JavaScript 是一种替代方案。
下面的示例是一个 PHP 页面,用于检查 HTTP 请求中传递的
resolution
变量。 如果它没有找到该分辨率变量,则会在页面上创建一段简短的 JavaScript,将该变量以及高度和宽度以重定向的方式传递回自身。 当然,当页面在重定向后再次加载时,所有变量都将被设置,PHP 将知道解析结果。最后我发现这是一个非常不令人满意的解决方案。 它可以工作,但是很丑陋,给 URL 增加了麻烦并且需要重定向。 尽管如此,它可能会激励某人发布更好的答案。 仅供参考,应得的信用,这个答案的灵感来自 这篇文章。
I was looking for this as well, but found none of these answers really answered the question! Indeed, there is no way for PHP to know the screen resolution since it is running on the server side. Since that information is not passed along in HTTP environment variables, we need another route. Javascript is one alternative.
The example below is a PHP page that checks for a
resolution
variable being passed in the HTTP request. If it does not find thatresolution
variable, then it creates a brief bit of JavaScript on the page that passes that variable and the height and width along in a redirect back to itself. Of course, when the page is loaded again after the redirect all the variables will be set and PHP will know the resolution.In the end I found this a pretty unsatisfactory solution. It works, but it is ugly, adding cruft to the URL and requiring a redirect. Still, it may inspire someone to post a better answer. FYI, credit where credit is due, this answer was inspired by this post.
我知道这不是最好的答案,所以不要投反对票。
I know this is not the best answer so spare the downvote.
有些人需要浏览器大小才能进行移动开发。 在某些情况下,这是重要信息。
使用 WURFL 和 WALL 可以解决这个问题,因为大多数手机不支持 JS。
Some people require browser size for mobile devoloping. This is essential information in some cases.
Using WURFL and WALL can get around this as most mobiles do not support JS.
无法使用 JS 获取监视器大小,您必须进行投票:)
Monitor size can't be obtained using JS, you have to make a poll :)
请注意,JS 可以检查浏览器的窗口大小,但该大小包括用户工具栏、滚动条等......浏览器中的实际工作空间区域取决于这些工具栏的大小。
Note, that JS can check the window size of browser, but this size includes user toolbars, scrollbars etc... Real workspase area in browser depends on those toolbars size.