|
-
Dec 31st, 2009, 07:57 PM
#1
Thread Starter
Addicted Member
How to use PHP display the date a page was last modified?
Hi All,
I am trying to display the date a page was last modified by using PHP. I am using a piece of code I read about somewhere. When I put it on my site, the same code produces different results on different pages.
The code below is the PHP code that I am using.
Code:
<?php
//Display the date a page was last modified
echo "Last modified on: " . date(" m F Y ", filemtime( $PATH_TRANSLATED ));
?>
I get the result below on one page.
Last modified on: 12 December 1969
And I get the result below on another page.
Notice: Undefined variable: PATH_TRANSLATED in /usr/local/apache2/htdocs/demo/footer.php on line 22
Last modified on: 12 December 1969
My site is not that ancient and was not built in 1969. How can I correct that error and make it display properly please? Or can someone help me with a better code to achieve this please?
Thanks in advance.
Menre
-
Dec 31st, 2009, 08:24 PM
#2
Re: How to use PHP display the date a page was last modified?
Check on how you're getting $PATH_TRANSLATED - something is failing there. In the second case, PHP is explicitly telling you it's undefined. When it's undefined or it's empty, you get this 1969 date.
You could also use getlastmod() instead, which doesn't require passing a path (but you need it to be called on the page you want to get the mod date for - so it won't work correctly for the parent if you put it on an included file).
-
Jan 1st, 2010, 08:06 PM
#3
Re: How to use PHP display the date a page was last modified?
In my thread here I used the code SambaNeko linked to. However, I noticed that the getlastmod() function on it's own returned the wrong time.
Until I put:
PHP Code:
<?php
date_default_timezone_set('your country/city');
?>
So it would look like this:
PHP Code:
<?php
date_default_timezone_set('your country/city');
echo " " . date ("F d Y H:i:s.", getlastmod());
?>
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jan 1st, 2010, 09:46 PM
#4
Re: How to use PHP display the date a page was last modified?
it's not the "wrong time," it's the server's time.
-
Jan 3rd, 2010, 07:24 AM
#5
Thread Starter
Addicted Member
Re: How to use PHP display the date a page was last modified?
Hi All,
Thanks to everyone that responded to my post. I followed your suggestions and was able to get it to work well.
I modified the code you posted to this.
Code:
<?php
//date_default_timezone_set('');
echo "Last updated " . date ("d M Y", getlastmod());
?>
Then the result was perfect as the code displayed what I wanted it to:
Once again, thanks.
Menre
-
Jan 29th, 2010, 01:47 AM
#6
Banned
Re: How to use PHP display the date a page was last modified?
I think you should change your time Jone, and may be any error in date function.
-
Jan 29th, 2010, 10:10 AM
#7
Re: How to use PHP display the date a page was last modified?
I don't know why you're making useless posts in old threads.
I almost wonder if you're a bot, since you're reviving old threads with random sentences and your signature is two separate links to the same website boasting "free sms."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|