Because any time I update website old website stays until I delete cookies. And I don't think every user will know how to delete cookies.
Asked
Active
Viewed 35 times
0
-
1Possible duplicate of [Remove a cookie](https://stackoverflow.com/questions/686155/remove-a-cookie) – mega6382 Oct 03 '17 at 08:11
-
A website doesn't not update because of cookies; unless your server is doing something really weird and shows old content based on old cookies (?!). No, you probably have a general caching problem, and while deleting cookies you're also deleting the cached site. You need to think about your caching strategy and set cache headers appropriately. http://xyproblem.info – deceze Oct 03 '17 at 09:32
2 Answers
0
Taken from that page, this will unset all of the cookies for your domain:
// unset cookies
if (isset($_SERVER['HTTP_COOKIE'])) {
$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
foreach($cookies as $cookie) {
$parts = explode('=', $cookie);
$name = trim($parts[0]);
setcookie($name, '', time()-1000);
setcookie($name, '', time()-1000, '/');
}
}
0
I delete cookies using this JS "deleteCookie(sName)":
function miTrim(cadena){
var seguir;
seguir = true;
while ( cadena != "" && seguir) {
if ( cadena.charAt(0)==' ' ) {
cadena = cadena.substring(1, cadena.length );
} else {
if( cadena.charAt(cadena.length-1) == ' ') {
cadena = cadena.substring(0, cadena.length-1 );
} else {
seguir = false;
}
}
}
return cadena;
}
function obtenerCookie( cookieBuscada ){
var todasCookies = document.cookie;
var matrizCookies = todasCookies.split(';');
var unaCookie;
var nombreCookie;
var posicion;
for ( var i= 0; i < matrizCookies.length; i++) {
unaCookie = matrizCookies[i];
posicion = unaCookie.indexOf("=")
if ( posicion > 0) {
nombreCookie = miTrim(unaCookie.substring(0,posicion));
if (nombreCookie == cookieBuscada) {
return unaCookie.substring(posicion +1);
}
}
}
return "";
}
function deleteCookie(sName) {
document.cookie = sName + "=" + obtenerCookie(sName) + "; expires=Fri, 31 Dec 1990 23:59:59 GMT;path=;";
}
-
Javascript is not the best solution to this problem because in certain cases some cookies are not reachable from javascript (and thus won't be affected by any JS code) – Calimero Oct 03 '17 at 08:25