View Full Version : cookies and screen resolution...
john_b
04-05-2010, 01:15 AM
I came across a website (http://scantips.com/) (the Survey link at the bottom of the page) that gives an indication of users' screen resolutions. Of course, it only shows results for people who visit that particular site but it is interesting nonetheless.
So I wondered about compiling similar stats for my own site - how is it done? I'd thought that the screen res would be part of the environment variables and that you could simply extract the details. Apparently not.
Further research reveals that cookies are the way to go. I have absolutely no experience of setting or using them. Indeed, I have a bit of an ethical 'block' against inflicting cookies on other people's machines; particularly when it is of no benefit to them, but is simply for my own indulgence.
I found bits and bobs which use PHP and also Javascript and my limited experiments confirm that it can set and read a cookie containing the information. Further research will be needed because you don't, for example, want to count the same client more than once...
...but that's another story. The algorithm seems to be something along the lines of "if the cookie has been set then read it, otherwise set one and then read it" but I'm just not understanding how the sequence of events works.
It appears that cookies are site-specific and if a browser requests a page from a server, then any existing cookie information specific to that site is sent along with the request. I can follow that, but what happens if no cookie has been set? The example I came across uses Javascript to set the cookie if none exists but I'm thinking that would happen too late for the browser to send the information to the server if it only requests the page once.
On the other hand, the script that I tested does seems to work but how does it do it?
If anyone could shed some light on what the sequence of events should be - in simple terms, please :) - then I'd be grateful.
John
donmcc
04-05-2010, 06:37 AM
Basically, it works like this. You set a script that attempts to read a cookie. If it exists, you get the data stored in it (usually only one or two variables). If it does not, the same script will create the cookie, and store data into it, or it may store new data into the old cookie. You must give an expiry date to a cookie, but by making it 100 years from now, you make the cookie persistent in reality.
However, you have never really explained 'why' you want to store a cookie. You don't need a cookie if you only want to track screen resolutions. For that you want to use JavaScript to report the resolution, and send that information back to your server. You only would use a cookie if you wanted to track sites that have changed their resolution since last visit.
john_b
04-05-2010, 09:01 AM
I think I'm starting to get a clearer picture of the sequence of events but I could not understand how PHP - which obviously processes data on the server - could check whether or not a cookie existed on the client machine and then do X if there was one or Y if there wasn't.
I'm now thinking - and please put me right if I'm barking entirely up the wrong tree - that cookies are domain specific and if a browser requests a page from a particular domain then the information contained in any cookies which were set by that site is sent along with the page request. Is that how it works?
If so then that's a major conceptual hurdle for me!
But to answer your other point, I actually don't want to set any cookies unless I have to. My feeling was that you might need to do so, if for no other reason that you need to know whether that browser has visited before, in which case you may or may not want to include the stats...
...however if Javascript can do the job on its own then I'm happy to explore that. I'm really no JS maven either, though, so really need to find out if and how it can send information back to the server.
John
Bo Aakerstrom
04-05-2010, 10:56 AM
As Don said - it is not that hard to get the information, but remember that while you can get statistics as regards to the resolution you don't know if the visitors are using their browsers maximised, or how many toolbars they gone and installed. So the information is not all that useful really.
terrie
04-05-2010, 12:21 PM
bo: it is not that hard to get the information, but remember that while you can get statistics as regards to the resolution you don't know if the visitors are using their browsers maximisedI always use my browser maximized but modified it and used the survey John pointed to and it read my screen res the same--1600x1200...
Terrie
It might be easier to use a service such as StatCounter (http://www.statcounter.com/) that will do all the hard work for you.
john_b
04-06-2010, 01:03 AM
Well I started looking at this because one of the sites I run makes use of a lot of photos which are all of a specific size. I was thinking it's maybe time to increase the size of them; a daunting prospect. One thing that leads me to this conclusion is that, while they look fine on my machine, figures point to the fact that - at 1024 by 768 - it's probably about as low res as they come and that times have moved on since I got it...
...and I also became vaguely interested in how cookies work... I know, I know - I really should get out more...;-)
John
john_b
04-06-2010, 01:06 AM
Oh, tsk, that would spoil all the fun...;-)
donmcc
04-06-2010, 04:48 AM
Yes, cookies are domain specific. Google can't read the cookies you write, and your server can't read Google's (if they leave any).
If you need to know that someone is a repeat user, then a cookie can tell you. You could store the time of last visit, total number of visits, or such things.
> so really need to find out if and how it can send information back to the server
It is easy to send things to the server. HTTP sends things to the server, and you can do a lot with just that. The trick is having something at the server that will handle the data you send, and that is where php comes in.
Steve Rindsberg
04-06-2010, 06:09 AM
And any cookie-based data is trustworthy only to the extent that the user allows you to set cookies and doesn't delete them.
Opera can be set to delete cookies when you quit, mine's set that way (paranoia, curmudgeonry, general crankiness, must be the tinfoil hat), so cookies wouldn't help much here. I doubt that most people bother, though I've no data to back that up. Hard to track that w/o cookies. ;-)
FWIW, while Google offers to preserve various user preferences, it doesn't work here.
Its cookies get munched along with the others when Opera quits.
donmcc
04-06-2010, 11:01 AM
You must not bank online Steve, without cookies most finance sites don't work.
Steve Rindsberg
04-06-2010, 11:32 AM
I do a little bit of online banking. In some cases, no problems. Opera allows cookies, it just doesn't hang onto them between sessions. That doesn't seem to be an issue.
In other cases, the fool sites spit at Opera and refuse to play, so I revert to MSIE, which I only use with sites I trust, so I tend to let it run with whatever its defaults are.
I'm trying to think what information the bank might require from one session to the next that'd make cookies necessary. And I'm too dim to come up with anything convincing at the moment.
Michael Rowley
04-06-2010, 02:53 PM
Steve:
I'm trying to think what information the bank might require from one session to the next that'd make cookies necessary. And I'm too dim to come up with anything convincing at the moment.When I logged on to my bank from my wife's laptop, because my own computer was temporarily out of action, the program twigged the difference and requested better identification (an eight-digit number). Could that be because it couldn't find a little Dutch cake with details of my previous session?
terrie
04-06-2010, 03:18 PM
steve: Opera can be set to delete cookies when you quit, mine's set that way (paranoia, curmudgeonry, general crankiness, must be the tinfoil hat)LOL!! Firefox can too and that's how I have mine set--for the same reasons...'-}}
Terrie
terrie
04-06-2010, 03:21 PM
steve: I'm trying to think what information the bank might require from one session to the next that'd make cookies necessary. And I'm too dim to come up with anything convincing at the moment.I do keep the cookies for a few sites--I use a Firefox add-on "CS Lite" to choose which sites I want to keep cookies--and one of the sets of cookies I keep is for my bank and the cookie(s) hold my state and some other info so I don't have to choose that each time...
Terrie
john_b
04-07-2010, 12:55 AM
Firefox also has an option to refuse cookies from 'third-party sites'. I assume these cookies are set by a site that you visit but on behalf of some other site?
My feeling is that they would generally be be concerned with advertising and/or tracking your browsing habits. With regard to what we said before, though, I have no idea of the mechanics here. How can you set a cookie for a domain other than your own? How does that information find its way to that other domain, given that you've probably never heard of it and wouldn't dream of visiting if you had?
I suppose I'm thinking of doubleclick and other soi-disant 'services'...;-(
John
Steve Rindsberg
04-07-2010, 06:14 AM
Steve:
When I logged on to my bank from my wife's laptop, because my own computer was temporarily out of action, the program twigged the difference and requested better identification (an eight-digit number). Could that be because it couldn't find a little Dutch cake with details of my previous session?
Michael,
Ah, interesting. And that number wouldn't be the password or user name/account number, I assume. In other words, it's not a case of the browser normally remembering those bits on your normal computer but not from your wife's laptop.
That reminds me that I need to check something online anyway, so let me try from a different computer ...
No, same procedure as last year, James. [obscure reference that, as a German translator, you'll surely understand ;-)]
So apparently this bank doesn't rely on cookies; it does, however, add a level of security beyond username/password. Once those are given, it displays a user-selected picture and asks for the answer to one of several questions. If it displays the wrong picture, you're to run away. If you don't know the answer to the extra question or mistype the answer, it runs away.
Steve Rindsberg
04-07-2010, 06:15 AM
LOL!! Firefox can too and that's how I have mine set--for the same reasons...'-}}
Terrie
Cute hat, Terrie.
By Reynolds?
Steve Rindsberg
04-07-2010, 06:18 AM
Opera also has the ability to refuse third-party cookies. They might be set as the result of the site you're visiting displaying content from another site (images, html content in frames, etc.)
It's not a question of them setting a cookie for a domain other than their own ... in theory that's simply not allowed. It's that the site you're visiting incorporates or otherwise references content from their domain, so they can set a cookie for their own domain, even though you've not explicitly visited it.
john_b
04-07-2010, 07:02 AM
Ah, now that is starting to make sense... another piece in the jigsaw so thanks for that!
That said, there would need to be a compelling reason for me to accept third-party cookies and I haven't come across one yet...;-)
John
Michael Rowley
04-07-2010, 07:52 AM
Steve:
same procedure as last year, JamesYes, that's not obscure to me or my wife, but we left Germany after New Years eve 1988, so I don't know if it's still on German TV every year. We enjoyed it!
The ID number doesn't have to be put in, for the browsers (FF & IE8) remember it; but I have to put in my 5-digit PIN every time. And yes, there's a picture, but only have to get suspicious if it's not the usual one (I don't have to answer any questions).
terrie
04-07-2010, 03:17 PM
steve: By Reynolds?None other...'-}}
Terrie
Steve Rindsberg
04-07-2010, 03:46 PM
Steve:
Yes, that's not obscure to me or my wife, but we left Germany after New Years eve 1988, so I don't know if it's still on German TV every year. We enjoyed it!
The ID number doesn't have to be put in, for the browsers (FF & IE8) remember it; but I have to put in my 5-digit PIN every time. And yes, there's a picture, but only have to get suspicious if it's not the usual one (I don't have to answer any questions).
We had a German post-doc student living with us for the past six months or so. She's the one who showed it to me originally and who told me that it's still de rigeur New Year's eve fare every year.
For anyone puzzled by all of this, look up "Dinner for One" on YouTube. The Wikipedia entry is interesting too.
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.