问题
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?
回答1:
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
回答2:
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:
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?
回答4:
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.
来源:https://stackoverflow.com/questions/10296772/sending-screen-resolution-via-a-form