jas168 Posted January 13, 2008 Share Posted January 13, 2008 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 Quote Link to comment Share on other sites More sharing options...
Daukan Posted January 13, 2008 Share Posted January 13, 2008 Are you sure your not recalling GetCartId() after you try emptying the cookie Quote Link to comment Share on other sites More sharing options...
jas168 Posted January 13, 2008 Author Share Posted January 13, 2008 yes i am calling GetCarId() after emptying the cookie. because i need to get whats in the cart. what is the right way to recall all the items in the cart? please advice thank you Quote Link to comment Share on other sites More sharing options...
revraz Posted January 13, 2008 Share Posted January 13, 2008 Well that function also sets a cookie if one doesn't exist. Quote Link to comment Share on other sites More sharing options...
jas168 Posted January 13, 2008 Author Share Posted January 13, 2008 what is the work around to retried the cart? Quote Link to comment Share on other sites More sharing options...
jas168 Posted January 14, 2008 Author Share Posted January 14, 2008 any one can help urgently Quote Link to comment Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 The work around is to fix the logic. Quote Link to comment Share on other sites More sharing options...
jas168 Posted January 14, 2008 Author Share Posted January 14, 2008 could you please give me an example of the logic thank you advance Quote Link to comment Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 If you unset the Cookie, don't set it again. Quote Link to comment Share on other sites More sharing options...
jas168 Posted January 14, 2008 Author Share Posted January 14, 2008 what if ineed to need to generate a new cookie after i unset cookie. is here a way around it? because its a shopping cart i am trying to build when click on empty cart, and when add new item it needs to greats a new cookie id. thanks Quote Link to comment Share on other sites More sharing options...
jas168 Posted January 14, 2008 Author Share Posted January 14, 2008 any one? Quote Link to comment Share on other sites More sharing options...
Pancake Posted January 15, 2008 Share Posted January 15, 2008 <?php setcookie("cartId", "", time() - 3600); ?> Should work just fine. even time()-1 should work. (I think) Quote Link to comment Share on other sites More sharing options...
jas168 Posted January 15, 2008 Author Share Posted January 15, 2008 yes i think this works in a normal situation, but i need to call function GetCartId() and i need an new cookie id after clear. but it don't seem o work, i a still getting the old cookie id. thanks Quote Link to comment Share on other sites More sharing options...
jas168 Posted January 15, 2008 Author Share Posted January 15, 2008 can some one help.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.