SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do servers come up wth user screen resolution statistics?

    Hi,

    I was looking to see if one could detect the screen resolution directly with PHP. But all I found were articles that said that that was impossible. That no such information is passed along with the HTTP call header information, and that one had to use javascript for that. But how are the statistics regarding user screen resolution formed then? How do servers know what your resolution is?

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Javascript. End of story. Use Javascript to send the information to the server in question.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    Javascript. End of story. Use Javascript to send the information to the server in question.
    So there are websites that send the following information to their servers: screen.width = x, screen.height = y? And on the basis of those data the servers compile their statistics? And how exactly would the sites send that code snippet to the servers?

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,858
    Mentioned
    206 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Frank S View Post
    And how exactly would the sites send that code snippet to the servers?
    AJAX, I would imagine.
    It would be quite simple to fire off a small AJAX request containing any relevant user statistics when the page loads.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Simplest JavaScript code to send the screen width and height to the server.

    Code:
    img = new Image();
    img.src = 'process.php?height=' + screen.height + '&width=' + screen.width;
    img = undefined;
    That runs process.php on the server passing it the width and height of the screen that the browser is displayed on.

    Most scripts would use a lot more code than that because most people don't realise that if you are just sending data from the web page to the server and don't need a response back that you can do it this way and only need three lines of code to pass as much information to the server as needed.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    AJAX, I would imagine.
    It would be quite simple to fire off a small AJAX request containing any relevant user statistics when the page loads.
    Agreed, Dave, it would. But who has such an AJAX script on their site? Have you or anyone you know ever received a request from anyone to include such a script somewhere in the code so that the servers can collect resolution data? And to you the same question, Stephen.

  7. #7
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,858
    Mentioned
    206 Post(s)
    Tagged
    12 Thread(s)
    I must admit, no I haven't.
    I think most people who are interested in such things would use Google Analytics.

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Frank S View Post
    Agreed, Dave, it would. But who has such an AJAX script on their site? Have you or anyone you know ever received a request from anyone to include such a script somewhere in the code so that the servers can collect resolution data? And to you the same question, Stephen.
    Quote Originally Posted by Pullo View Post
    I must admit, no I haven't.
    I think most people who are interested in such things would use Google Analytics.
    Pullo has answered Frank's question. Anyone using Google Analytics (or any other similar script that captures statistics about visitors) has a script in their page that captures such data.

    I can't see any reason why anyone would bother to write code to do it themselves rather than to use a script such as Analytics that does it for you.

    In the case of the script that I included in my post above that code was written as an example of how data can be easily sent to the server from JavaScript in situations where no response from the server is required using a lot less code than you need when the JavaScript needs to be able to receive and process a response. I used the screen width and height simply as two fields to represent whatever variables you want to be able to pass from JavaScript to a server side script. It was just a coincidence that the script was an exact fit to what was being asked. See http://javascriptexample.net/ajax08.php for my original use of that script. The example script following that one is a far more useful implementation of that concept of sending data to the server as it provides a way for the server to perform specific processing when someone stops viewing the page (it has nothing to do with what the Op was asking about though).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,858
    Mentioned
    206 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by felgall View Post
    In the case of the script that I included in my post above that code was written as an example of how data can be easily sent to the server from JavaScript in situations where no response from the server is required using a lot less code than you need when the JavaScript needs to be able to receive and process a response.
    That's a neat trick felgall and I must confess I didn't know it before, so thanks for sharing
    However, saying that, I was vaguely aware that some companies use images in HTML emails to find out if people read them (the emails that is), so I guess this would be a similar tactic, as in this case, too, there is no response needed from the server.

  10. #10
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Pullo has answered Frank's question. Anyone using Google Analytics (or any other similar script that captures statistics about visitors) has a script in their page that captures such data.
    OK, but how many years are there between the resolution stats being readily available and the appearance of Google Analytics? At least a number of years. How did servers compile their stats before GA?

  11. #11
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Frank S View Post
    OK, but how many years are there between the resolution stats being readily available and the appearance of Google Analytics? At least a number of years. How did servers compile their stats before GA?
    The same way that analytics does it - using an ajax call of one type or another. The version I posted above works in any browser that supports images. The more conventional XMLHttpRequest type of call has been available to use since IE4. The XDomain and XHR2 calls that analytics actually uses now have only been added in more recent browsers.


    Basically any browser from Netscape 2 on has had the ability to send the information to the server in one way or another.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  12. #12
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    The same way that analytics does it - using an ajax call of one type or another. The version I posted above works in any browser that supports images. The more conventional XMLHttpRequest type of call has been available to use since IE4. The XDomain and XHR2 calls that analytics actually uses now have only been added in more recent browsers.
    Basically any browser from Netscape 2 on has had the ability to send the information to the server in one way or another.
    OK, but who had that script/code snippet included in their code? Not the normal websites, I would think. Or are the statistics based upon the users of search engines like Google?

  13. #13
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Frank S View Post
    OK, but who had that script/code snippet included in their code? Not the normal websites, I would think. Or are the statistics based upon the users of search engines like Google?
    It used to be really common for web sites to include a counter on their page that displayed how many visitors the site had received. Capturing any stats about the visitors would have been a part of that script. There were literally hundreds if not thousands of different hit counter scripts around for people to choose from. Hardly anyone used search engines back then as they didn't find much in the way of useful results. Directories built by real people were far more popular back then. Google didn't come along until much later.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  14. #14
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It used to be really common for web sites to include a counter on their page that displayed how many visitors the site had received. Capturing any stats about the visitors would have been a part of that script. There were literally hundreds if not thousands of different hit counter scripts around for people to choose from.
    That sounds plausible. Thanks for clearing it up, Stephen.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •