Forum Moderators: coopster

Message Too Old, No Replies

cookie check

on the same page

         

Tastatura

4:15 am on Mar 12, 2006 (gmt 0)

10+ Year Member



Hi all,
I would like to check and see if my visitor’s browser accepts cookies, and do it on the first page they landed on. To best of my knowledge ‘setcookie’ function does not give a confirmation back if the cookie was already set. Is this possible and if so how?

Some notes:
-I guess I can first set cookie using JavaScript, and then read it with PHP, but user can have JS disabled...
-Can I force page refresh with PHP? How? (header()? - I am bit of a noob to php)
-Will SE’s (when crawling the site, listing in SERPS, etc.) see a page refresh as a ‘bad’ thing, or hey don’t care?

Thanks a lot

jatar_k

3:07 pm on Mar 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



from the manual
[php.net...]
Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE arrays.

so you're right you can't do it on the same page.

the refresh would be bad in regards to se's I would think

>> set it with js and read it with php

I am not sure if that would work or not.

what exactly are trying to acheive?

Tastatura

8:46 pm on Mar 12, 2006 (gmt 0)

10+ Year Member



what exactly are trying to acheive?

I am trying to gather stats to see how many of my visitors have javascript enabled and how many accept cookies (with java script I am grabbing their screen resolution).
What I am (was) thinking of doing is to set cookie with PHP and then set another cookie with JS (storing screen resolution data), and then retrieve that info via PHP and save it to file/db.
I think there are few ways to skin this cat, but I am trying to balance page load time vs coding complexity vs server time.
I read up on the subject and a lot of “JS checks” suggest using a form, then tring to change a value, and then see if it was actually changed – I tried it but abandon this approach (nothing too significant, mostly personal preference).
I wanted to determine if the cookie was set on the first page the visitor landed on, just because it would give me more accurate results – meaning that if I have a visitor that views only one page (page that they landed on) and leaves afterwards without going to any of my other pages – I wanted to capture them as well. If I have to wait for them to go to the second page, I can’t capture ‘one page hitters’.
Flow with this approach is that if cookies are disabled, I don’t know for sure if JS is enabled or not (cookies might be off, but JS might be on, however I will not know about it).
Any suggestions on best ways to collect cookie and JS info is greatly appreciated.