Page 1 of 1
PHP header last-modified
Posted: Sun Oct 08, 2006 3:30 am
by duncan
How can this code be modified to send a date which is 1 day ago and a fixed hour of 8:oo p.m. ?
Code: Select all
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
Posted: Sun Oct 08, 2006 3:46 am
by volka
strtotime is your friend
Code: Select all
<?php
$ts = strtotime('yesterday 8pm');
echo date('D, d M Y H:i:s', $ts);
?>
Posted: Sun Oct 08, 2006 7:13 am
by duncan
Can you rewrite that code into header last-modified format?
Posted: Sun Oct 08, 2006 7:43 am
by timvw
Why don't you try it yourself? Or lookup some tutorial/howto on http so that you get a better understanding... (I'm aware that this may sound 'harsh' but it's written with good intentions)
Posted: Sun Oct 08, 2006 7:46 am
by duncan
I've tried but all the different combinations that I have tried do not work.
Posted: Sun Oct 08, 2006 7:48 am
by timvw
At least show us what you've tried... (we don't have a magic ball that knows what's going wrong for someone...)
Posted: Sun Oct 08, 2006 9:43 am
by duncan
I've tried among others:
Code: Select all
<?php
$ts = strtotime('yesterday 8pm');
header("Last-Modified: " . gmdate('D, d M Y H:i:s', $ts) . " GMT");
?>
Code: Select all
<?php
$ts = strtotime('yesterday 8pm');
header("Last-Modified: date('D, d M Y H:i:s', $ts)");
?>
Code: Select all
<?php
$thour=date('08');
$tmin=date('00');
$tsec=date('00');
$tmonth=date('n');
$tday=date('d');
$tyear=date('Y');
$bdate=mktime($thour,$tmin,$tsec,$tmonth,$tday,$tyear);
header("Last-Modified: $bdate");
?>
Code: Select all
<?php
header("Last-Modified: " . gmdate("D, date("d")-1, M Y 08:00:00") . " GMT");
?>
Posted: Sun Oct 08, 2006 12:50 pm
by volka
Code: Select all
$header = "Last-Modified: " . date('D, d M Y H:i:s', strtotime('yesterday 8pm')) . " GMT";
// echo $header;
header($header);
Posted: Sun Oct 08, 2006 3:32 pm
by duncan
Your answer yields the current date not yesterday's date according to Firefox.
Posted: Sun Oct 08, 2006 3:43 pm
by onion2k
duncan wrote:Your answer yields the current date not yesterday's date according to Firefox.
What are you using to view the header? The code Volka posted worked fine for me using both Firefox's 'page info', and Web Dev Toolbar's 'view response headers'.
Posted: Sun Oct 08, 2006 3:45 pm
by volka
Hm, not with my version of php and my pc's clock.
What does
Code: Select all
$header = "Last-Modified: " . date('D, d M Y H:i:s') . " GMT";
echo $header, "<br />\n";
$header = "Last-Modified: " . date('D, d M Y H:i:s', strtotime('today 8pm')) . " GMT";
echo $header, "<br />\n";
$header = "Last-Modified: " . date('D, d M Y H:i:s', strtotime('yesterday 8pm')) . " GMT";
echo $header, "<br />\n";
print?
Posted: Sun Oct 08, 2006 4:36 pm
by duncan
Volka, your code is correct but for some reason firefox' "view page info" shows it totally incorrect (even the year is wrong and an expire date is shown, which previously was blank). When I use a specialized web to view the headers, it is shown correctly. I thought that firefox was a reliable source of info... guess not!