Jump to content

Redirect after deletion of comment and timestamp update = no cache revalidation


SuperBlue

Recommended Posts

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.

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.