Sending screen resolution via a form

2019-09-12 14:42发布

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?

4条回答
唯我独甜
2楼-- · 2019-09-12 14:47

You will have to fill in the screen resolution via JavaScript and then send it. This is not a safe method, since anyone who wanted to could change the value in the hidden field... But it will work:

// Fill in forms with screen resolution (jQuery)
$('#screenWidth').val(screen.width);
$('#screenHeight').val(screen.height);

And simply use a couple of hidden fields:

<input type="hidden" name="screenWidth" id="screenWidth"/>
<input type="hidden" name="screenHeight" id="screenHeight"/>
查看更多
祖国的老花朵
3楼-- · 2019-09-12 14:59

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

查看更多
等我变得足够好
4楼-- · 2019-09-12 15:00

The previous example should work:

Javascript

document.getElementById('debug').value = screen.width + 'x' + screen.height;

Are you getting any errors? Which browser are you using? OS?

查看更多
可以哭但决不认输i
5楼-- · 2019-09-12 15:07

As other people have said, the screen object works. Just saying "It doesn't work" doesn't help with finding the problem out. If you have jQuery correctly loaded, it will just work.

screen.width + "x" + screen.height

This returns "1280x1024" in my case.

See http://jsfiddle.net/KVQM4/ for an example of it working. If you can create something similar to show how it doesn't work, or give us a bit more information as to the error.

查看更多
登录 后发表回答