urgent php cookie kill problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jas168
Forum Newbie
Posts: 3
Joined: Sun Jan 13, 2008 9:25 am

urgent php cookie kill problem

Post by jas168 »

Hi i have a problem trying to kill a cookie session below is the codes i create the cookie

function GetCartId()
{
// This function will generate an encrypted string and
// will set it as a cookie using set_cookie. This will
// also be used as the cookieId field in the cart table

if(isset($_COOKIE["cartId"]))
{
return $_COOKIE["cartId"];
}
else
{
// There is no cookie set. We will set the cookie
// and return the value of the users session ID

session_start();
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
return session_id();
}
}


i just want to kill this cookie i have try so many ways but no luck
<?php
setcookie("cartId", "", time() - ((3600 * 24) * 2));

?>

any ideas..

thanks advance
User avatar
Inkyskin
Forum Contributor
Posts: 282
Joined: Mon Nov 19, 2007 10:15 am
Location: UK

Re: urgent php cookie kill problem

Post by Inkyskin »

Try this:

Code: Select all

setcookie("cartId", "", time() - 3600, "/");
User avatar
jas168
Forum Newbie
Posts: 3
Joined: Sun Jan 13, 2008 9:25 am

Re: urgent php cookie kill problem

Post by jas168 »

Inkyskin wrote:Try this:

Code: Select all

setcookie("cartId", "", time() - 3600, "/");
Just no luck, the cookie id still the same
User avatar
jas168
Forum Newbie
Posts: 3
Joined: Sun Jan 13, 2008 9:25 am

Re: urgent php cookie kill problem

Post by jas168 »

do you think its the
return session_id();
causing the problem?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: urgent php cookie kill problem

Post by VladSun »

The cookie will be deleted at next page browsing - maybe this cause you this problem.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply