PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
duncan
Forum Newbie
Posts: 8 Joined: Sun Sep 17, 2006 7:07 am
Post
by duncan » Sun Oct 08, 2006 3:30 am
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");
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Oct 08, 2006 3:46 am
strtotime is your friend
Code: Select all
<?php
$ts = strtotime('yesterday 8pm');
echo date('D, d M Y H:i:s', $ts);
?>
duncan
Forum Newbie
Posts: 8 Joined: Sun Sep 17, 2006 7:07 am
Post
by duncan » Sun Oct 08, 2006 7:13 am
Can you rewrite that code into header last-modified format?
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sun Oct 08, 2006 7:43 am
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)
duncan
Forum Newbie
Posts: 8 Joined: Sun Sep 17, 2006 7:07 am
Post
by duncan » Sun Oct 08, 2006 7:46 am
I've tried but all the different combinations that I have tried do not work.
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sun Oct 08, 2006 7:48 am
At least show us what you've tried... (we don't have a magic ball that knows what's going wrong for someone...)
duncan
Forum Newbie
Posts: 8 Joined: Sun Sep 17, 2006 7:07 am
Post
by duncan » Sun Oct 08, 2006 9:43 am
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");
?>
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Oct 08, 2006 12:50 pm
Code: Select all
$header = "Last-Modified: " . date('D, d M Y H:i:s', strtotime('yesterday 8pm')) . " GMT";
// echo $header;
header($header);
duncan
Forum Newbie
Posts: 8 Joined: Sun Sep 17, 2006 7:07 am
Post
by duncan » Sun Oct 08, 2006 3:32 pm
Your answer yields the current date not yesterday's date according to Firefox.
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Sun Oct 08, 2006 3:43 pm
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'.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Oct 08, 2006 3:45 pm
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?
duncan
Forum Newbie
Posts: 8 Joined: Sun Sep 17, 2006 7:07 am
Post
by duncan » Sun Oct 08, 2006 4:36 pm
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!