note 30514 modified in function.getlastmod by danbrown

From: Date: Sun, 20 Jul 2008 00:23:04 +0000
Subject: note 30514 modified in function.getlastmod by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141839@lists.php.net to get a copy of this message
I found issues using getlastmod() to test whether or not I was successful in setting the Last Modified date in the header. The code below shows the same Last Modified date before and after I set the Last-Modified header. <?php //True modified date $modified = date ("F d Y H:i:s.", getlastmod()); //artificial modified date - sent to header $last_modified = gmdate('D, d M Y H:i:s T', (time() - 43200)); //caching prevention header("Last-Modified: $last_modified GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // HTTP/1.0 $getlast_modified = date ("F d Y H:i:s.", getlastmod()); print "True modified date(Before): $modified <p /> Date sent to header(After): $getlast_modified"; ?> I then used the PEAR, HTTP_Request class which worked, the Last-Modified date updates everytime it is requested, the desired effect. <?php require 'HTTP/Request.php'; $r = new HTTP_Request('http://www.sample.com/page.php'); $r->sendRequest(); $response_headers = $r->getResponseHeader(); print $response_headers["last-modified"]; ?> --was-- I found issues using getlastmod() to test whether or not I was successful in setting the Last Modified date in the header. The code below shows the same Last Modified date before and after I set the Last-Modified header. =====getlastmod <? //True modified date $modified = date ("F d Y H:i:s.", getlastmod()); //artificial modified date - sent to header $last_modified = gmdate('D, d M Y H:i:s T', (time() - 43200)); //caching prevention header("Last-Modified: $last_modified GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // HTTP/1.0 $getlast_modified = date ("F d Y H:i:s.", getlastmod()); print "True modified date(Before): $modified <p /> Date sent to header(After): $getlast_modified"; ?> I then used the PEAR, HTTP_Request class which worked, the Last-Modified date updates everytime it is requested, the desired effect. ======HTTP_Request <? require 'HTTP/Request.php'; $r = new HTTP_Request('http://www.sample.com/page.php'); $r->sendRequest(); $response_headers = $r->getResponseHeader(); print $response_headers["last-modified"]; ?> http://php.net/manual/en/function.getlastmod.php

« previous php.notes (#141839) next »