How to delete cookie on codeigniter

I do not know how to delete a cookie. I want when I submit the form. The cookie is also deleted. I am trying to delete_cookie ("name") but it does not work. I think because cookie I created javascript . Please check my code to fix this problem.

This is my text box:

 <input name="cargo_no" type="text" class="validate[required]" id="cargonumber" onchange="setCookie('cargonumberC', this.value, 365);"/> 

and this is javascript

 function setCookie(cookieName, cookieValue, nDays) { var today = new Date(); var expire = new Date(); if (!nDays) nDays=1; expire.setTime(today.getTime() + 3600000*24*nDays); document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString(); } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } document.addEventListener('DOMContentLoaded', function() { var themeSelect = document.getElementById('cargonumber'); var selectedTheme = readCookie('cargonumberC'); if (selectedTheme) { themeSelect.value = selectedTheme; } }); 
+8
php cookies session-cookies codeigniter
source share
3 answers

Using Codeigniter, put it in the save method of your controller:

Try:

 delete_cookie('name', $domain, $path); 
+12
source share

You can remove the cookie from CodeIgniter. Use a cookie helper like

 $this->load->helper('cookie'); delete_cookie("name"); 
+8
source share

You cannot delete the cookie. Browser (or user) to delete cookies. But you can force the browser to automatically delete the cookie by setting the cookie expiration date to a past date. Here is a javascript example.

 function deleteCookie(cookieName, cookieValue) { document.cookie = cookieName+"="+escape(cookieValue) + ";expires=Thu, 01 Jan 1970 00:00:01 GMT;"; } 
-3
source share