detecting resolution
netzdamon
Status: New User - Welcome
Joined: 29 Jun 2006
Posts: 3
Reply Quote
Was happy when i found this page and saw the script to detect the screen solution but ended up being disappointed as i have been for a while now. Trying to find a elegant solution for detecting a browser resolution and storing it into a mysql database using php. I know the detection must be done with in javascript. I have tried to store it in a cookie with javascript and retrieve it with php but the only way i can make that happen is to refresh the page after the cookie is stored so php can see it. I have also tried passing it through a url and grabbing it that way but i don't like the fact the users resolution shows up on every page the counter is on. Anyone have a good solution to pass it into my database using javascript/php? Tried to find a way with ajax xml-rpc but had no luck finding the info i needed.

Thanks in advance!
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
:: Quote ::
I know the detection must be done with in javascript. I have tried to store it in a cookie with javascript and retrieve it with php but the only way i can make that happen is to refresh the page after the cookie is stored so php can see it.


That's how it is, php is executed server side, before the page is sent to the user, and javascript is executed client side, after the page is sent.

So anything javascript does will always be after what php does, thus forcing solutions like refresh of page, which isn't really that bad.

First test for cookies of course.

then set cookie with javascript

on top of each page, have php look for that cookie, if cookie is set, then do the screen resolution condition, else do nothing, the default action that is.

Have javasrcript refresh the page if and only if the cookie was successfully set. That works fine.
Back to top
netzdamon
Status: New User - Welcome
Joined: 29 Jun 2006
Posts: 3
Reply Quote
Well thats what i already have going. I was not completly happy with the solution hoping i could take advantage of the new ajax hype and have javascript drop it right into my database for me or something to that effect. Just being picky i guess. Thanks for setting me straight.
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
oh, you could do it with ajax, but that's really overkill, and wouldn't solve the page reload question anyway.

You still need to have cookies set, you still need to test them with php on each and every page load, it's not a real difference.

The one major difference is that every gui browser out there except maybe dillo on linux will support the basic javascript cookie test, cookie creation, then on success page reload, whereas you have to custom script your ajax for msie/firefox/safari, losing reliability and gaining nothing.

Sure you could write to the database with ajax, but that doesn't change a thing, you could just as well write to it on the next page load, and that would be a lot easier to code, and it would be more reliable, and, most important: it's simple, fast, and easy. That's always my favorite scripting solution if it will do the job.
Back to top
netzdamon
Status: New User - Welcome
Joined: 29 Jun 2006
Posts: 3
Reply Quote
Thanks a lot for the help jeff, i'll stick to what i first implimented just a bit confused on the new ajax xml-rpc stuff. Sticking with the current code i wrote.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours