I would like for the homepage of a site to display only the three most recent news items or updates in chronological order. I'm currently using php to reference a directory that contains all news updates as individual flat text files. Each file is named for the date it was created (20090722 would be a news item created on 22 July, 2009).
The script looks into the directory and selects the first three files encountered to be included on the home page. The files are named by their creation date which will result in a logical order.
Here's the script that calls and displays the three most recent updates.
Is there a better way to accomplish this? Are there security problems with this? Thanks for any help.
The script looks into the directory and selects the first three files encountered to be included on the home page. The files are named by their creation date which will result in a logical order.
Here's the script that calls and displays the three most recent updates.
PHP:
<?php
if ($handle = opendir('updates/')) {
$i = 0;
while(($file = readdir($handle)) && $i < 3) { // Limits the script to display only
if ($file != "." && $file != "..") { // 3 items if they aren't directory references
include ("updates/$file");
$i++;
}
}
closedir($handle);
}
?>
Is there a better way to accomplish this? Are there security problems with this? Thanks for any help.
Last edited: