Help with update script.

Discussion in 'PHP' started by WalterWhite13, Aug 12, 2013.

  1. #1
    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 [​IMG]
     
    WalterWhite13, Aug 12, 2013 IP
  2. EmmanuelFlossie

    EmmanuelFlossie Active Member

    Messages:
    159
    Likes Received:
    11
    Best Answers:
    2
    Trophy Points:
    65
    #2
    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.
     
    EmmanuelFlossie, Aug 12, 2013 IP
  3. WalterWhite13

    WalterWhite13 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    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!
     
    WalterWhite13, Aug 12, 2013 IP
  4. EmmanuelFlossie

    EmmanuelFlossie Active Member

    Messages:
    159
    Likes Received:
    11
    Best Answers:
    2
    Trophy Points:
    65
    #4
    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
     
    EmmanuelFlossie, Aug 13, 2013 IP
  5. WalterWhite13

    WalterWhite13 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    Thanks a lot for taking the time to help me.. I've got that done!
     
    WalterWhite13, Aug 13, 2013 IP
  6. EmmanuelFlossie

    EmmanuelFlossie Active Member

    Messages:
    159
    Likes Received:
    11
    Best Answers:
    2
    Trophy Points:
    65
    #6
    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):
     
    EmmanuelFlossie, Aug 13, 2013 IP
  7. WalterWhite13

    WalterWhite13 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    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?
     
    WalterWhite13, Aug 13, 2013 IP
  8. EmmanuelFlossie

    EmmanuelFlossie Active Member

    Messages:
    159
    Likes Received:
    11
    Best Answers:
    2
    Trophy Points:
    65
    #8
    just add a column labeled pageNames and give them a name, then in your while loop echo out the $r['pageNames']
     
    EmmanuelFlossie, Aug 14, 2013 IP