Hi people... I am new to this forum and im sort of a beginner to PHP.. Im trying to make a script that shows, in a file which I can include on the side part of my index page, the date of a last update and plus underneath that a list of which pages I have updated. So for an example if the last time I updated was Tuesday and I only edited my news and index page it would say August 6, 2013 - Home Page Updated. - News Headlines Updated. Then underneath it would show the other latest updates.. like so: August 6, 2013 - Home Page Updated. - News Headlines Updated. August 5, 2013 - Staff Updated. August 2, 2013 - Home Page Updated. - Forum Updated. - Join Page Updated. I would also like to be able to set a limit on how many updates can be shown.. I had a friend who had this script years ago and I remember he done it through a .txt file and CHMOD the txt file to have written permissions. Then their was updates.php and on every page I wanted to generate an update status I would include a few lines of some scripting at the top of the file.. Plus I would list the page names and what I wanted it to show in either the txt file or updates file like index.php > Home Page Updated... However I have lost contact with him and their is no way of me finding it. I had a go and and got: <?php $pages = array( 'Main Page' => 'index3.php', 'Staff' => 'staff.php', 'News Headlines' => 'news.php', ); $list = array(); foreach($pages as $page => $file) { $date = filemtime($file); if(!isset($list[$date])) { $list[$date] = array(); } array_push($list[$date], $page); } krsort($list); foreach($list as $date => $pages) { echo date('F j, Y', $date) . "<br />\n"; foreach($pages as $page) { echo "- $page Updated<br />\n"; } } ?> But this doesn't work correctly as it starts a new date even if I update two files in the same day... Anyway I was just wondering if anybody has any idea of how this script would be made? I am in desperate need to get it so any help would be great.. I am really unsure of how to go about it.. Thanks people and I hope to hear something back
I would suggest using mysql if you can. Because writable files on a site is not healthy! I would just run a cronJob every day catching the files update time, then save it in mysql If you need a bit of help let me know.
Thanks for the reply! I have been reading up on cron jobs but I'm not very familiar with how they work and what commands to set etc... I would greatly appreciate it if you could help!
Ok so what you need to do first is create a mysql table Create an id => integer, value 11, index, auto increment Create a page => varchar, value 500 Create a datetimestampon update CURRENT_TIMESTAMPNoCURRENT_TIMESTAMPON UPDATE CURRENT_TIMESTAMP How do you create a table? => http://www.w3schools.com/sql/ Once that is done, let me know
ok than create a php file create a mysql connection <?php $fileName = 'test.php'; $fileTime = filemtime($filename); mysqli_query($conn,"INSERT INTO mytable (page, date) VALUES ('".$fileName."', '".$fileTime."' "); ?> Code (markup): if you want to do multiple files just do a foreach $array = array('file1.php','file2.php'); foreach ($array as $key){ $fileTime = filemtime($key); mysqli_query($conn,"INSERT INTO mytable (page, date) VALUES ('".$fileName."', '".$fileTime."' "); } Code (markup): if your host supports cron do a cronjob, or else do a manual browser load than to echo info $q = mysqli_query($conn,"SELECT DISTINCT model FROM mytable WHERE page='title1.php' ORDER BY date DESC"); while ($q = mysli_fetch_array($q)){ echo it out } Code (markup):
Great, I'll try this out now thanks again.. Also, I want it to display the updated files by names I give them,e.g: index.php I want to display Home Page Updated instead of index.php updated.. How can I go about doing this?
just add a column labeled pageNames and give them a name, then in your while loop echo out the $r['pageNames']