Delete cookie from browser?

后端 未结 6 1684
野的像风
野的像风 2021-02-19 04:03

Is there any way of instructing a web browser to completely delete one\'s cookie set with PHP?

I do not want to expiry it or wait for the brows

6条回答
  •  無奈伤痛
    2021-02-19 04:25

    I wrote this plugin for me and works correctly.

    (function($) {
        $.cookieAllDelete = function(doc)
        {
            var cookie_date = new Date();
            var cookies = null;
    
            cookies = doc.cookie.split(';');
            cookie_date.setTime(cookie_date.getTime() - 1);
    
            for(var i=0; i < cookies.length; i++) 
            {
                var cookie_name = cookies[i].split('=')[0];
                try {
                    if (cookie_name.length > 0)
                        doc.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
                } catch(ex) {}
            }
        }
    })(jQuery);
    
    jQuery.cookieAllDelete(document);
    

提交回复
热议问题