Jump to content

Setting Cookies in Javascript, Then Clearing them in PHP


Gafaddict

Recommended Posts

I am using the Tool Man script, a script that allows one to "drag and drop" the position of a list of elements. It uses cookies to pass the information from one page to the next.

 

When I try to use PHP to clear the value of this cookie, it doesn't work.

I have a suspicion that this has something to do with the fact that the cookie was set in JavaScript, because if I try to clear a cookie which I set in PHP, it clears easily.

 

The code I am using to clear is: setcookie("list_boxes", "", time() - 3600);

 

The script that Tool Man uses to set cookies can be found at: http://tool-man.org/source/org/tool-man/cookies.js

 

Any ideas?

Link to comment
Share on other sites

There should be no difference in a cookie just because of where it came from.  Have you looked at the actual cookie contents at each stage inside your browser?

 

Another thought is whether the JavaScript is recreating the cookie based on the presence of other cookies or another factor.

Link to comment
Share on other sites

You must use the same parameters that were used when the cookie was created. When the parameters don't match, you are trying to clear a different cookie that probably doesn't exist.

 

The set function is setting the path to /. In order to match that cookie, you need to set the 4th parameter in the setcookie() function call to '/'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.