Forum Moderators: coopster

Message Too Old, No Replies

Cookies disappearing on me

Problem with Cookies

         

hueymoo

11:58 am on Oct 25, 2005 (gmt 0)

10+ Year Member



I have a php app that is to set/update a cookie.
I am using
setcookie("hdclimit", $_GET['CLIMIT'], time() + (3600 * 24 * 364) + 5,"/", ".v4.dir.com");
to set the cookie.
and then
if (isset($_COOKIE[hdclimit]))
{ print("cookie has been set<br>");
$default_climiter = $_COOKIE[hdclimit];
}
else { print("The cookie wasn't set");$default_climiter = "10";}

to determine whether or not the cookie has been set.

The first time I enter the web page, I receive the not set message and upon exiting I can find the cookie file in the C:\Documents and Settings\username\Cookies directory.

The second time I enter the web page, I receive the cookie found message and the cookie value is used.

When I exit from the web page, the cookie is gone from the C:\Documents and Settings\username\Cookies directory.

The 3rd time I enter the web page, I again receive the cookie not found message.

What causes this cookie to disappear on me. Is it not just supposed to update?

TIA
D

hueymoo

7:11 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



I have set a cookie in a php script using the following

setcookie("hdclimit", $_GET['CLIMIT'], time() + (3600 * 24 * 364) + 5,"/", ".v4.#*$!.com");

the cookie is correctly set on the first pass through. I then exit the browser and am able to find the cookie in the C:\Documents and Settings\username\Cookies directory and it does have the correct value.

The second time I go to the web site, the cookie is retrieved and used, then appears to be deleted as when I exit the browser, the cookie is no longer in C:\Documents and Settings\username\Cookies directory and if I go back into the web site, it is not retrieved
How do I keep the cookie and update it everytime the web site is used without it disappearing on me?
TIA
D

coopster

5:42 pm on Oct 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, hueymoo.

There are other applications that may be removing your cookie. Are you certain you don't have a firewall setting, Norton Antivirus, Zone Alarm, spyware, browser setting, etc. that is cutting your cookie?

mcibor

10:09 am on Oct 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Moreover the cookies don't appear in _COOKIE in the time when they are set with setcookie.
It is so because first cookies are read and then set.

There's no way around it.

As for disappearing cookies see if you're not deleting them yourself.

Eg. this code would work as you described:

member.php?bla=1:

setcookie("bla", $_GET['bla'], time() + (3600 * 24 * 364) + 5, "/", ".v4.#*$!.com");
if(!$_COOKIE['bla']) header("Location: member.php");

In the first sweep you set the cookie to 1, but COOKIE is not set!
In the second sweep you delete the cookie: GET['bla'] is empty, but COOKIE is set!
Hope this may be of any help.
Michal Cibor