Php can detect IP, hostname, client agent etc. Can php detect client browser monitor size/resolution?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
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.
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.
I know this is not the best answer so spare the downvote.
Monitor size can't be obtained using JS, you have to make a poll :)
You'll have to use PHP together with JavaScript, like in this example:
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.