View Full Version : Display content for Scheduled dates
atechstl 11-13-2009, 11:18 AM I have been asked to work include some content on a website starting December 1st and to remove it at the end of the month.
To manually input this and remove it is all too easy. I am looking for a reference or an example to input this content ahead of time and have it displayed for the one month durration automatically.
The website is coded in .shtml.
Any advice appreciated.
mattle 11-13-2009, 12:05 PM The website is coded in .shtml.
Are you serious?
You need to start by understanding what SSI even is (quite often, just a gateway to another server-side scripting technology)...
http://en.wikipedia.org/wiki/Server_Side_Includes
http://httpd.apache.org/docs/1.3/howto/ssi.html
This is extremely simple to do in any programming language, however it does not sound like you understand the basic concepts at play here. What you want to do is possible using strictly SSI (I think), however you could really benefit from a scripting language here.
PHP would do this. Something like this might do it:
<?php
if (time() >= strtotime('December 1, 2009') && time() < strtotime('January 1, 2010')){
echo 'All your stuff here'; // Or you could include a file that has it all using include('/path/to/file.ext');
}else{
echo "It's over, go home";
}
?>
mattle 11-13-2009, 12:47 PM PHP would do this. Something like this might do it:
<?php
if (time() >= strtotime('December 1, 2009') && time() < strtotime('January 1, 2010')){
echo 'All your stuff here'; // Or you could include a file that has it all using include('/path/to/file.ext');
}else{
echo "It's over, go home";
}
?>
# php
<?
echo date("m-d-Y") . "\n";
if (time() >= strtotime('December 1, 2009') && time() < strtotime('January 1, 2010')){
echo 'All your stuff here'; // Or you could include a file that has it all using include('/path/to/file.ext');
}else{
echo "It's over, go home";
}
?>
11-13-2009
It's over, go home
Aw man...it's over before it even began!!! :stickout:
So, two people you basically pick apart for getting it wrong (PHP is obviously not my day job), but where's your example of getting it right, please? ;)
Teach.
Or try this instead:
<?php
if (time() < strtotime('January 1, 2010') && (time() >= strtotime('December 1, 2009'))){
echo "December stuff here";
}else{
echo "Non December stuff here";
}
?>
atechstl 11-13-2009, 03:54 PM Thanks for the help guys. I can certainly do PHP but I will have to change the file extension.
I will try it out.
bigfan 11-13-2009, 11:29 PM bear - Nothing wrong with your first code (as you probably know), but the message should have been along the lines of "You're either too early or too late." I think the message is what mattle was chuckling about. :)
Yup, fair enough (though the latter one works far better). I just get a little frustrated sometimes when people don't help. ;)
bigfan 11-14-2009, 10:56 AM OK, here's some help in the form of an alternative suggestion :) if (date('ym') == '0912') {
echo 'December 2009';
} else {
echo 'Not December 2009';
}
mattle 11-15-2009, 01:26 PM Yup, fair enough (though the latter one works far better). I just get a little frustrated sometimes when people don't help. ;)
I'm always willing to help...that's why I posted links that explain SSI so that the OP could get a better understanding of the technology.
The website is coded in .shtml.
That's a big red flag that the OP has a hole in their fundamental knowledge of dynamic web content. How is it not helping to point someone to reference material? For that matter, how is it helping to write someone's code for them, offering no explanation of what the code actually does and why it works?
tim2718281 11-16-2009, 10:30 PM And there's the interesting question of how one tests whatever solution one chooses.
I suppose what one can do is have a server-side script that generates a date and timestamp, then includes the latest file whose name is less than that date and timestamp.
So if you had a set of files
190001010000.inc
200911160800.inc
200911230800.inc
200912031200.inc
the web server would include 200911160800.inc till 08:00 on November 23, when it would switch to including 200911230800.inc (which might be a blank file.)
The idea here is because there are no code changes, the change management is easier.
And there's the interesting question of how one tests whatever solution one chooses.
Change the dates in the script. ;)
nwmcsween 11-16-2009, 11:40 PM Ruby, but this shouldn't be handled as such
puts "Something" if Time.now.month == 12
mattle 11-17-2009, 09:41 AM Change the dates in the script. ;)
Or if you're just testing proof of concept, use CLI...no need for script changes
<?
$time = (isset($argv[1]) ? strtotime($argv[1]) : time());
if ($time < strtotime("12/1/2009"))
doSomething();
else if ($time < strtotime("1/1/2010"))
doSomethingElse();
else
doYetSomethingElse();
?>
#php myScript.php "11/30/09"
executes doSomething()
#php myScript.php "12/10/09"
executes doSomethingElse()
#php myScript.php "1/1/10"
executes doYetSomethingElse()
#php myScript.php
executes appropriate fn based on current date
|