homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

How do you know if cookies are available?

10+ Year Member

Msg#: 3402510 posted 10:30 pm on Jul 23, 2007 (gmt 0)

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.





WebmasterWorld Senior Member 10+ Year Member

Msg#: 3402510 posted 5:05 am on Jul 24, 2007 (gmt 0)

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

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





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

Msg#: 3402510 posted 6:41 am on Jul 24, 2007 (gmt 0)

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.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved