0

I am wondering if anybody knows of any function available to get the screen resolution of a monitor connected to a server in PHP.

I do NOT want the resolution of any client computer. I am looking to put together some basic information about a few servers that I can get access to intermittently through a PHP script running on the Apache servers and one of the important pieces of information is the screen resolution.

David
  • 176,566
  • 33
  • 178
  • 245
O Genthe
  • 131
  • 8
  • Don't think it can be done with PHP: https://stackoverflow.com/questions/1504459/getting-the-screen-resolution-using-php – dmikester1 Feb 11 '19 at 20:42
  • 2
    @dmikester1 - That is asking about client side screen resolution, not server side. – O Genthe Feb 11 '19 at 20:43
  • 1
    Maybe try using `shell_exec("some_shell_script_to_get_screen_res")` and use PHP to execute a shell script on the server that you are trying to get the screen res for. I don't know of a way to get the resolution of the current machine with just raw PHP. – Nick Tiberi Feb 11 '19 at 20:45
  • 1
    some (majority) servers do not have any monitors attached, are you sure that you need this? – Iłya Bursov Feb 11 '19 at 20:46
  • 1
    I suspect the approach will be finding any command line tool, separate from PHP, which will output information about the monitor and as suggested in a comment above to execute that command line tool from PHP code and read its output. – David Feb 11 '19 at 20:48
  • 2
    Wait... you want to know the resolution of the monitor physically connected to the server? I'm not sure WHY you need this, but you can do it. Shell out and call a unix call to find the information (like xrandr in ubuntu). But, keep in mind a couple of things. 1) many web hosts do NOT have physical monitors connected to each server. and 2) Many shared hosts will block access to the system calls you need to find this out. – R. Smith Feb 11 '19 at 20:50
  • Yes, I want the resolution of the monitor connected to servers completely under my control but not in the same physical location as me. Thanks for the shell_exec suggestions. That seems to be the best and easiest way to go. – O Genthe Feb 11 '19 at 20:55

1 Answers1

2

The only way I can think of that might work is executing an actual terminal command with exec, get the result and find the resolution in it. But please be aware of the dangers of exec and read the "Warning" section.

You properly need the correct permission to execute this kind of commands. So it depends on the type of server, operating system, etc. if this works.

n9iels
  • 678
  • 5
  • 17
  • 1
    Yeah, what he said. That's the only way, really. – R. Smith Feb 11 '19 at 20:51
  • Thanks. I can't believe I missed this. I am putting it down to it being late and being tired ;). I used the following on a variety of Ubuntu servers and it works well: `` – O Genthe Feb 12 '19 at 08:17