Creating date specific links?
Asked by
dangdang (
193)
August 6th, 2008
I would like to link to a file that updates on a daily basis. The only thing that changes is the day of the month (1–31) in the name of the file. (ex. http://www.example.com/file27.pdf) Where the 27 is the day of the month. I would like to make 1 link that would update itself according to today’s date. Is this possible? If so, how?
Observing members:
0
Composing members:
0
6 Answers
If PHP is available on your server, you can do it by linking to this address: http://www.example.com/file<?=date(‘d’)?>.pdf
JavaScript will be a little trickier, and you’ll have to keep in mind that links won’t work for users with JavaScript disabled. I’ll post a script for that in a little while if no one else gets to it first.
I think I got it:
<script type=“text/javascript”>
var d = new Date();
document.write(”<a href=\“http://www.example.com/file”+(d.getDate())+”.pdf\”>here</a>”);
</script>
PHP.. This would be easy
<?php echo date(“j”);?>
Just plug that in where the changing date would go in the url.
edit :: Never mind. It looks like you got it.
another edit :: the lowercase j is the day without the leading zero, the d has a leading zero so the 7th would come out as 07.
Of course, when Javascript is disabled, the link won’t work (which isn’t the case for PHP).
That said, you could also use PHP to load the file and make sure the link doesn’t change at all. There are so many roads that lead to Rome ;-)
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.