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.

4
  • set its date to back date it will be deleted automatically. Commented Mar 16, 2013 at 7:33
  • document.cookie = 'update_name=;expires=Thu, 01 Jan 1970 00:00:01 GMT;'; check this answer: stackoverflow.com/a/10593045/921204 Commented Mar 16, 2013 at 7: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. Commented Mar 16, 2013 at 7: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. Commented Mar 16, 2013 at 8:36

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.