SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    page last updated

    I ahve a side bar called leftnav.php that is included on every one of my pages on my website. I was wondering if there is a script that can be included on this page that tells me when the page that i am on was last updated not the time leftnav.php was last updated?(which is what all the scrips i have tryed have done!) check out www.munnaz.com for a look see. Please help

    Munnaz

  2. #2
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why do you want to do it like that? if you are including the files in the main file then simply pass the timestamp of the main content file being included or even the update timestamp from the db for the content to the lastUpdated.php file over http
    something like this
    PHP Code:
    include('http://domname.com/lastUpdated.php?timestamp='.$timestamp); 
    I hope you can figure out the logic involved

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm new at this stuff and it would really help if you explained it for my stupid simple mind
    sorry
    thanks

  4. #4
    SitePoint Addict fesh's Avatar
    Join Date
    Jan 2005
    Location
    Jackson, New Jersey
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one way to do it would be to create a script that analyzes the last time (according to the timestamp) the navigation was updated. you could create a cookie each time the user vists the page that establishes the time they view the page. and, logically, if the user's timestamp is after the update timestamp, bam display that it had been updated.
    Fesh
    imagine what it's going to be like

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks sounds good except i wouldn't have a clue how to do anything u just said. Is there any way you could write up how to do it here?? please.... i have put this in the spot on www.munnaz.com on the left hand side and it just says the date the left nav was updated!
    <?php echo ''.date("d/m/Y", filemtime($_SERVER['PHP_SELF'])); ?>
    please anything u do would be a great help!
    thanks heaps
    munnaz

  6. #6
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    belfast
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is very specific to my own purpose but it might help:

    PHP Code:

    $filename 
    __FILE__;

    function 
    last_updated($filename)
            {

                
    // Display the date
                // eg. Jan 25 2004
                
                
    $todaydiff "5";//server-to-GMT time
                
    $timeadjust = ($todaydiff 60 60);
                
    $gmt_today_date date("M d Y",time() + $timeadjust);
                
                
    $yestdiff "19"//24hrs - server-to-GMT time = 19hrs
                
    $timeadjust = ($yestdiff 60 60);
                
    $gmt_yest_date date("M d Y",time() - $timeadjust);
                
                
    $last_modified_file filemtime($filename);
                
    $last_modified_file_day gmdate("M d Y"$last_modified_file);
                
    $last_modified_file_time gmdate("g:ia"$last_modified_file);
                
                if (
    $last_modified_file_day == $gmt_today_date){
                    
    $last_modified 'Today ' $last_modified_file_time;
                }
                elseif (
    $last_modified_file_day == $gmt_yest_date){
                    
    $last_modified 'Yesterday ' $last_modified_file_time;
                }
                else{
                    
    $last_modified $last_modified_file_day;
                }
                return 
    $last_modified;
            } 
    This takes the current page's filename and finds the local time. Depending on when the file was last updated it outputs, today, yesterday or if more than 3 days old the date.

    It takes into consideration the time difference between local and server times.

    This script prob has a few faults etc but it works for me (feel free to point out any of these faults).

    What you could do is on the page you updated make $filename a global variable. So on every page you update:

    //index page
    $filename = index.php

    //events page
    $filename = events.php

    This will use at filename as the input and return the last updated time.

    To use the output from the code on your include page do:
    PHP Code:
    <?php echo("<b>Last Updated: " $last_modified "</b>");?>

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks but i put the code exactly as you have it and it shows nothing.
    do i have to put the top code on all the pages or in the headtags and then put the bottom one in the spot where i want it to show or do i have to change something in the code? soz to be such a dumbarse but what can i say?
    thanks
    munnaz

  8. #8
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    belfast
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, put this in a file called update.inc
    PHP Code:
    function last_updated($filename)
            {

                
    // Display the date
                // eg. Jan 25 2004
                
                
    $todaydiff "5";//server-to-GMT time
                
    $timeadjust = ($todaydiff 60 60);
                
    $gmt_today_date date("M d Y",time() + $timeadjust);
                
                
    $yestdiff "19"//24hrs - server-to-GMT time = 19hrs
                
    $timeadjust = ($yestdiff 60 60);
                
    $gmt_yest_date date("M d Y",time() - $timeadjust);
                
                
    $last_modified_file filemtime($filename);
                
    $last_modified_file_day gmdate("M d Y"$last_modified_file);
                
    $last_modified_file_time gmdate("g:ia"$last_modified_file);
                
                if (
    $last_modified_file_day == $gmt_today_date){
                    
    $last_modified 'Today ' $last_modified_file_time;
                }
                elseif (
    $last_modified_file_day == $gmt_yest_date){
                    
    $last_modified 'Yesterday ' $last_modified_file_time;
                }
                else{
                    
    $last_modified $last_modified_file_day;
                }
                return 
    $last_modified;
            } 
    Include udpate.inc to your side bar page like so: require ("update.inc");

    On your modifed page set a variable at the top called filename and set this to the name of your updated page:

    $filename = events.php;

    to call the update function put this at the top of your side bar page:

    $updated = last_updated($filename);

    To use the value of $updated on your side bar add this code to where you want the updated time displayed:

    PHP Code:
    <?php echo("<b>Last Updated: " $updated "</b>");?>
    Hope that helps
    Last edited by ronanmagee; Jul 5, 2005 at 01:41.

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks man 4 ur help

  10. #10
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    belfast
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No Problem - did you get it to work?

    If not you can send me a few files and when I get time I'll have a go at it.

    Ronan

  11. #11
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    na thanks for your help man but i just put
    <?php echo .date("d/m/Y", filemtime($_SERVER['PHP_SELF'])); ?>
    on every page! lol took ages but o well i have been trying to get that include to work for ages but what can i do i am not too smart at this sort of stuff! thanks neway
    munnaz

  12. #12
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    belfast
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    grand so :-)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •