Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How do you know if cookies are available?



10:30 pm on Jul 23, 2007 (gmt 0)

10+ Year Member

Why do I ask...

My website often links to pages where php adds the session id (sid) to the end of the url when cookies are not avaiable; but not all the time - like when I generate the url from within my php script.

So, when cookies are not available I want to add the sid on the end of my urls. (I don't want to add it on when cookies are available - I want to do it when php would have done it).

Previously I used to have a bit of code that set a session variable, then read it on the next page to detect cookies. This is no good if the session id is retained within the url (with non-cookie browser settings) as it my will think cookies are set.

So, how do I know cookies are really available and not just on a url parameter.

You may ask, why do I want to know.
1. Clean urls when cookies are enabled.
2. I want to track non-cookie browsers in my stats, as the same user may retutn several times with different session ids.




5:05 am on Jul 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I would have tried the following way, not tested but I think it should work.

$val = 1;
setcookie("test_ex", $val);





6:41 am on Jul 24, 2007 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

From the PHP website:

Cookies will not become visible until the next loading of a page that the cookie should be visible for.

So, set the cookie, then re-load the page before checking it.



Featured Threads

Hot Threads This Week

Hot Threads This Month