0

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?

John Vasiliou
  • 977
  • 7
  • 27
  • 48

4 Answers4

1

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"/>
aurbano
  • 3,324
  • 1
  • 25
  • 39
  • thank you - I've already tried this and I cannot get it to work. Also in regards to it not being safe only a select few will use it to benefit themselves anyway so they won't be messing around with it. – John Vasiliou Apr 24 '12 at 11:21
  • Do you have jQuery loaded? The screen object works in every browser since Navigator 4.0x and Internet Explorer 4.0x – aurbano Apr 24 '12 at 11:27
  • It doesn't work in Google Chrome, let me see if it works in Firefox. – John Vasiliou Apr 24 '12 at 11:27
  • Check for jQuery, the screen object works in Chrome, Firefox, Opera, IE..., if you don't use jQuery just access the value directly: document.getElementById("screenWidth").value = screen.width; – aurbano Apr 24 '12 at 11:28
  • I've got the jquery library called in the head - – John Vasiliou Apr 24 '12 at 11:31
  • Name: screenWidth: screenHeight: Email: Nope. Here is the website - http://channel944.com/useragent.php – John Vasiliou Apr 24 '12 at 11:35
  • For just javascript, see this page. no need to load a large library like jQuery for a simple task http://www.quirksmode.org/dom/w3c_cssom.html – rickyduck Apr 24 '12 at 12:11
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

Tobias Krogh
  • 3,768
  • 20
  • 14
1

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?

72lions
  • 680
  • 2
  • 7
  • 12
  • And also make sure that your javascript is executed when the dom is already loaded so that you can actually find the 'debug' field that I am using in this example. – 72lions Apr 24 '12 at 11:39
  • OK stupid question but do you have an element with id set to debug? And if yes, then do you execute the Javascript on dom load? – 72lions Apr 24 '12 at 11:55
  • I do, I have . How do I execute the javascript on dom load? – John Vasiliou Apr 24 '12 at 12:10
  • I believe I've now executed the javascript on dom load using: Still doesn't work. Any ideas? – John Vasiliou Apr 24 '12 at 12:24
1

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.

anothershrubery
  • 20,461
  • 14
  • 53
  • 98
  • But this doesn't allow me to send it using a php form. When I send it using php forms it doesn't work and I haven't a clue why. I did include a direct link to the website, here it is again - http://channel944.com/useragent.php – John Vasiliou Apr 24 '12 at 11:50