SuperBlue Posted January 3, 2012 Share Posted January 3, 2012 I'm having a problem with a bit of code, which works for everything else, but just doesn't work when used for deletion of comments. The relevant code: mysql_query("UPDATE $table SET LastEdited = '$time' WHERE PID = '$ID'", $Connection) or die(mysql_error()); header('Location: /'. $URL; This works, the resource is getting updated. What doesn't work is the revalidation after the redirect. The code I'm using for caching is: header("Cache-Control: must-revalidate"); header("Last-Modified: ".gmdate("D, d M Y H:i:s", $Header['LTIME'])." GMT"); header("Etag: $etag"); header('Content-type: text/html; charset=UTF-8'); if ((@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $Header['LTIME']) && ( trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)) { header("HTTP/1.1 304 Not Modified"); exit; } Its the exact same code used when posting comments on the site, aside from the query of cause. What i don't get, is why i have to hit update in my browser, to get it to re-validate. The $etag will only be updated if the sites source have been changed. Quote Link to comment https://forums.phpfreaks.com/topic/254257-redirect-after-deletion-of-comment-and-timestamp-update-no-cache-revalidation/ Share on other sites More sharing options...
SuperBlue Posted February 21, 2012 Author Share Posted February 21, 2012 Ok. I'm pretty sure i have this problem solved now. Turned out the location header alone was redirecting trough a 302 response, rather than a 303. After i added the 303 thing, everything now appears to behave as expected. If the server just responds with a 302, it appears that the browser just re-loads the page from the cache, without performing the re-validation that the server originally requested for the given page. When using a 303 however, it would seem that it properly re-checks the cache headers of the page. Quote Link to comment https://forums.phpfreaks.com/topic/254257-redirect-after-deletion-of-comment-and-timestamp-update-no-cache-revalidation/#findComment-1319528 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.