Forum Moderators: coopster

Message Too Old, No Replies

Cookies Problem

Cookies are not Destroying

         

umerkk

9:23 am on Jun 19, 2007 (gmt 0)

10+ Year Member



Hi
I have a Code logout.php, which unser the session and destroy cookies, But it do not destroy the cookies, i have page which checks if cookie is there then show "sdfs" else show "No Cookies", But Even after Logout it show me that cookie is present,

My Logout.php code is

<?php

include("../../includes/session_check.php");
sessioncheck();

if ($_SESSION['loggedin'] == '1') {
$rlReturnUrl = $_REQUEST['rlReturnUrl'];
setcookie ("username");
setcookie ("usernameScreenName");
session_unset();
session_destroy();
header ("Location: $rlReturnUrl");
} else {
echo "No User Currently Logged In";
}
?>

Habtom

9:30 am on Jun 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



setcookie("screenname", "", -1); can destroy it.

Hab

umerkk

5:36 pm on Jun 19, 2007 (gmt 0)

10+ Year Member



No, This one is also not destroying

setcooki("usernameScreenName", "", -1);

Any Other Suggestions?

mcibor

7:49 pm on Jun 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To delete a cookie you need to set it with past delete:
[php.net...]

setcookie ("username", "", time() - 3600*365);
setcookie ("usernameScreenName", "", time() - 3600*365);

If this doesn't help, then I can only think about two solutions:

1. You set cookie from a root folder, but delete from a subfolder - it won't work
2. Try to destroy cookie with javascript.

Hope this information will help you
Regards
Michal

eelixduppy

7:50 pm on Jun 19, 2007 (gmt 0)



You could also try unset [php.net](), although it should work with what you have above.

mcibor

8:27 pm on Jun 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Eelix, but unset will not remove a cookie...
Because unset works on a server, whereas cookie is set on user's computer.

Regards
Michal

eelixduppy

8:32 pm on Jun 19, 2007 (gmt 0)



That is true. I'm not myself today...Trying to redeem myself ;) -- it will, however, "unset it" for anything after that line in the script; it's only temporary though.

Habtom

6:25 am on Jun 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> setcooki("usernameScreenName", "", -1);

Did you put it correctly or you just mistyped it here:

It should be like this:
>> setcookie("usernameScreenName", "", -1);

Habtom

mattclayb

11:39 am on Jun 20, 2007 (gmt 0)

10+ Year Member



I believe the problem exists because of the way you are 'setting' the cookie.

You are only defining one variable for the cookie, the name, ie -

setcookie("userName");

setcookie likes to have at least 3 defined variables, the name, the value of the cookie (whats contained in it) and the amount of time until it should expire. ie -

setcookie("name", "value", "life_of_cookie");

When you miss the "life_of_cookie" out, they begin to behave very unpredictably. In ie it will not write to the users cookie directory. They get stored in memory, and can't be destroyed by the php function.

If you give your original setcookie all values it expects, then you shouldn't have a problem.

umerkk

5:53 pm on Jun 20, 2007 (gmt 0)

10+ Year Member



I have alrady come up with the solutions

setcookie("usernameScreenName", "", "", "/");

Now it works

mcibor

8:45 pm on Jun 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So the problem was location - you set it up in the root directory, but wanted to delete from sub. Therefore "/" locating the cookie in root dir could finally delete it.

Glad you got it to work!