Forum Moderators: coopster

Message Too Old, No Replies

Problem http last-modified

         

foodstyling

3:18 pm on Sep 30, 2006 (gmt 0)

10+ Year Member



I try to get the header http last-modified to give the last modified date from the row 'date' of a mysql database. First I tried to retrieve the row with the modified date (which works allright). The retrieved date can be checked here: <snip> - (just under the title), but the Last_Modified date in the header gives:

HTTP/1.1 200 OK
Date: Sat, 30 Sep 2006 13:16:11 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) PHP/
4.3.11
X-Powered-By: PHP/4.3.11
Last-Modified: Tue, 19 Jan 2038 03:14:07 GMT
Connection: close
Content-Type: text/html

The code I use to retrieve and output the date must be wrong but I can't find the error. Thanks for help.:

$row_date['date'] = gmdate();
$colname_date = "1";
if (isset($_SERVER['date'])) {
$colname_date = (get_magic_quotes_gpc())? $_SERVER['date'] : addslashes($_SERVER['date']);
}
mysql_select_db($database_recettes, $recettes);
$query_date = sprintf("SELECT `date` FROM recettes WHERE receptID = %s", $colname_date);
$date = mysql_query($query_date, $recettes) or die(mysql_error());
$row_date = mysql_fetch_assoc($date);
$totalRows_date = mysql_num_rows($date);

$last_modified = gmdate('D, d M Y H:i:s', $row_date['date']) . ' GMT';
// did the browser send an if-modified-since request?
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
// parse header
$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);

if ($if_modified_since == $last_modified) {
// the browser's cache is still up to date
header('HTTP/1.0 304 Not Modified');


exit;
}
}

header('Last-Modified: ' . $last_modified);

[edited by: dreamcatcher at 6:08 pm (utc) on Sep. 30, 2006]
[edit reason] No URLs, thanks. [/edit]

lmo4103

3:38 pm on Sep 30, 2006 (gmt 0)

10+ Year Member



As I understand it, the IF_MODIFIED_SINCE is a negotiation that occurs outside of php.

You just do the header('Last-Modified: ' . $last_modified); and the determination of whether to regard the page as modified or not modified will be done correctly, based on the $last_modified.

The format of the date in $last_modified must be an accepted format, though.

I think something like this works:
Sun, 06 Nov 2005 14:59:42 GMT

foodstyling

3:53 pm on Sep 30, 2006 (gmt 0)

10+ Year Member



Thanks for your answer, but I don't understand yoyr statement about negotiation outside PHP. Does it means that my myql code is not right and how can I correct it?

lmo4103

4:04 pm on Sep 30, 2006 (gmt 0)

10+ Year Member



Tue, 19 Jan 2038 03:14:07 GMT is in the future and so it can't be "304 Not Modified" for several years yet.