Search code examples
phpjavascripthtmlformsscreen-resolution

Sending screen resolution via a form


I've got it sending the user agent already:

<input type='hidden' name='user-agent' value='<?php echo $_SERVER['HTTP_USER_AGENT']; ?>'/><input type="submit" value="Send User Agent" />

I've done my research and there is some code out there that sadly doesn't work. It's other people with problems asking for help themselves.

How can I go about sending screen resolutions using php forms?


Solution

  • you will not get the screen resolution from the server IMHO... you could let the form be rendered and then use javascript to update a form input with the correct information

    HTML

    <input id="browser-resolution" type="hidden" name="resolution" value="">
    

    and afterwards as a script

    <script>
      document.getElementById('browser-resolution').value = screen.width + "x" + screen.height;
    </script>
    

    EDIT: added fiffle