|
-
Aug 19th, 2003, 10:58 AM
#1
Thread Starter
Lively Member
delete cookies [RESOLVED]
hello,
I have 3 pages that deals with cookies:
addcookies.php
<?
$i=0;
$prod=$_COOKIE['prod'];
while (list ($name, $value) = each ($prod))
$i++;
$prod=$_GET['prod'];
setcookie("prod[$i]",$prod);
?>
delcookies.php
<?
$prod=$_COOKIE['prod'];
while (list ($name, $value) = each ($prod))
setcookie("prod[$name]","");
?>
showcookies.php
<?
$prod=$_COOKIE['prod'];
while (list ($name, $value) = each ($prod))
echo "$name == $value<br>\n";
?>
this cookies are holding array as values
I am keep failing to delete all the array there is always one cell in the array that is left...
anybody see something wrong in this code?
if you cant help me base only on this code then tomorrow I will upload it to my server and you will see what I mean...
Yair
Last edited by yair24; Sep 8th, 2003 at 01:13 AM.
-
Aug 20th, 2003, 09:11 AM
#2
Frenzied Member
first you have to set the cookie correcty. you set the name and value but not the time. and deleteing a cookie doesn't mean just delete the value.
to set a cookie you have to do this
setcookie("name_of_cookie", "value_of_cookie", time(),"/");
to delete a cookie you have to do the exact oposite of when you set it. but the only thing that changes is teh time as you do the same time but just minus it.
setcookie("name_of_cookie", "value_of_cookie", -time(),"/");
your way will not work.
-
Aug 20th, 2003, 03:24 PM
#3
Stuck in the 80s
Originally posted by phpman
to delete a cookie you have to do the exact oposite of when you set it. but the only thing that changes is teh time as you do the same time but just minus it.
Not necessarily. You can delete a cookie just by doing:
Code:
setcookie('cooke_name', '', time() - 3600);
You don't have to specify the value or path.
-
Aug 20th, 2003, 05:53 PM
#4
Frenzied Member
I know but he was deleting the value only with no time.
you should have a path as I have seen many problems arise because the path was forgotten.
-
Aug 20th, 2003, 09:53 PM
#5
Lively Member
why dont they just make a "deletecookie()" function?

-morrowasted
-
Aug 20th, 2003, 10:30 PM
#6
Stuck in the 80s
Originally posted by phpman
I know but he was deleting the value only with no time.
you should have a path as I have seen many problems arise because the path was forgotten.
I've never had a problem with it.
why dont they just make a "deletecookie()" function?
Why don't ya ask them?
-
Aug 20th, 2003, 10:54 PM
#7
Frenzied Member
Originally posted by The Hobo
I've never had a problem with it.
you will 
actually, morrowasted had the problem. read this
http://www.htmlforums.com/showthread...threadid=23074
Last edited by phpman; Aug 20th, 2003 at 11:01 PM.
-
Aug 21st, 2003, 01:00 AM
#8
Stuck in the 80s
For SETTING the cookie, yes, I agree with you and do understand why you should do that.
For DELETING the cookie, I don't see why you would have a problem with not specifying the path?
-
Aug 21st, 2003, 07:02 AM
#9
Lively Member
phpman, you go to htmlforums?
ah, the days of my PHP youth... i'd probably make the same mistake today, actually, if i had never done cookies before!

-morrowasted
-
Aug 21st, 2003, 09:29 AM
#10
Frenzied Member
Originally posted by The Hobo
For SETTING the cookie, yes, I agree with you and do understand why you should do that.
For DELETING the cookie, I don't see why you would have a problem with not specifying the path?
because it has to be the same as when you created it. so specifing the path should be in there. I guess if you delete it without the path and it works that is fine, I just don't do it that way. if I create it one way I delete it the same way. save all teh trouble.
but the fact remains that he didn't set the cookie correctly anyway. 
morrowasted: think about it
-
Aug 21st, 2003, 10:14 AM
#11
Thread Starter
Lively Member
thanks :)
thanks for the help.
Yair
-
Aug 21st, 2003, 11:47 AM
#12
Stuck in the 80s
Originally posted by phpman
I guess if you delete it without the path and it works that is fine, I just don't do it that way. if I create it one way I delete it the same way. save all teh trouble.
If no trouble exists, no trouble can be saved.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|