0

I want to clear all the cookies of a particular website in the users browser when a person runs a php script in my website.

hablema
  • 540
  • 1
  • 5
  • 17
  • 2
    [What have you tried?](http://whathaveyoutried.com/) – sczizzo Jun 13 '12 at 21:28
  • Possible duplicate? http://stackoverflow.com/questions/1399901/how-can-my-website-delete-another-sites-cookies – Mike Jun 13 '12 at 21:31
  • possible duplicate of [how to delete all cookies of my website in php](http://stackoverflow.com/questions/2310558/how-to-delete-all-cookies-of-my-website-in-php) – mgraph Jun 13 '12 at 21:37

2 Answers2

1

Go through all of your cookies and run this:

setcookie("cookie_name", $site_name, time()-timeout);

Rob Wagner
  • 4,391
  • 15
  • 24
  • You can only modify the cookie visible from within your website, so if you're trying to delete another website's cookies you can't. Your question was a bit confusing, but I thought this is what you were looking for. – Rob Wagner Jun 13 '12 at 21:34
  • Can i delete all the cookies from that site without entering a particular cookie name? – hablema Jun 13 '12 at 21:34
  • You can't delete another site's cookies from your site. You can only delete your cookies. – Rob Wagner Jun 13 '12 at 21:35
  • I meant i know the cookie names from the site, but there are around 20 of them, so instead of writting 20 lines can i do it in a single line by just giving the site name? – hablema Jun 13 '12 at 21:36
  • Check out the answer to this question. It has a function for deleting all the cookies in your domain. http://stackoverflow.com/questions/2310558/how-to-delete-all-cookies-of-my-website-in-php – Rob Wagner Jun 13 '12 at 21:39
  • @hablema - Try a `for` loop in this case to delete the 20 cookies for **YOUR** site. But why have so many cookies in the first place? – Ed Heal Jun 13 '12 at 21:40
  • Yeah 20 cookies seems a little excessive. – Rob Wagner Jun 13 '12 at 21:41
  • @Recursed - too many cookies you get fat and then life gets difficult. – Ed Heal Jun 14 '12 at 19:00
1

You cannot do this as the browser maintains the cookies for that web site, not your web site. This would be a breach in the contract between the web server and the browser.

Also it is up to the browser to handle cookies in the way that it sees fit - after all a cookie is asking the browser to do the web server a favour by storing some info between web page visits from that server (domain).

But if the cookies are from your domain/server then you can ask the browser to either make them time out or give them an invalid value.

Ed Heal
  • 59,252
  • 17
  • 87
  • 127