1

I want to javascript or php script delete the cookie that i was set up with javascript now i want to delete that cookie.

here this is my javascript:

<script type="text/javascript">
    var url = window.location.hash;
    var result = url.split('?');
    var advertise = result[1].split("&");
    var id = advertise[0].split("=");
    document.cookie = "update_id=" + id[1];
    var name = advertise[1].split("=");
    document.cookie = "update_name=" + name[1];
</script>

how to delete or clear this cookie using javascript or php code.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
phireak
  • 45
  • 2
  • 8
  • set its date to back date it will be deleted automatically. – Yogesh Suthar Mar 16 '13 at 07:33
  • `document.cookie = 'update_name=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';` check this answer: http://stackoverflow.com/a/10593045/921204 – techfoobar Mar 16 '13 at 07:34
  • this cookie stored to update data in database , after updated i want to delete this cookie immediately.so next time i will get new cookie. – phireak Mar 16 '13 at 07:36
  • after clicked submit button i want delete it immediately..if not yet delete it , it will get the old cookie name . so it will duplicate data when i save it into my database. – phireak Mar 16 '13 at 08:36

1 Answers1

1

You can do like this in JavaScript :

Just call delete_cookie function by passing your cookie name.

function delete_cookie(cookie_name)
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime (cookie_date.getTime() - 1);
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
} 

You can do like this in PHP :

setcookie("cookie_name", "", time()-3600);
Dead Man
  • 2,880
  • 23
  • 37