Welcome to WebmasterWorld Guest from 23.20.241.155

Forum Moderators: DixonJones & mademetop

Message Too Old, No Replies

Cookies On / Off - how to know - "now"?

Using PHP

     
7:31 am on Jun 17, 2004 (gmt 0)

10+ Year Member



The subject and description really sum it up but - I'm workin ona project that I need to know wether or not cookies are even turned on before I bother trying to run my script or if I merely report back a message saying "too bad".

Feedback?

8:37 am on Jun 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to set the cookie and then read it back to see it was set. Note that you can do this in JavaScript easily, in Perl/PHP/ASP, you need to set the cookie in one page and then redirect to another page to read it back as the browser only send the cookie data on each page request.
3:34 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Yes I reconize what you refer to with PHP cookiesets n requests.

So how do I use javascript for the task?
Would it work to set a cookie on javascript and then right after request it with PHP?

10:10 am on Jun 18, 2004 (gmt 0)

10+ Year Member



Using JavaScript:

A cookie can be set in the browser "immediately" and checked "immediately".
JavaScript functions are called AFTER a page request

Using PHP/ASP/...:

A cookie can be set AS the user request a page.
A cookie can be checked AS the user requests a SUBSEQUENT page.
PHP functions are called AS a page is requested, ie. BEFORE any JavaScript is run.

;)

7:53 pm on Jun 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just a thought, and I've not tried it, but couldn't you set a cookie with php and try to read it with javascript, all on the same page?
12:50 pm on Jun 19, 2004 (gmt 0)

10+ Year Member



Yes you can, and it works, but if you're using JS to check the cookie wouldn't you use the same to set it?

;)

1:03 pm on Jun 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you're using JS to check the cookie wouldn't you use the same to set it?

Ooh yes. You can tell I don't do this sort of thing very often :)

 

Featured Threads

Hot Threads This Week

Hot Threads This Month