By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,889 Members | 1,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,889 IT Pros & Developers. It's quick & easy.

To get last modified date of website

rishidadhich
P: 9
hi all,

I want to get the last modified date of a website,
but I am completely clueless how to do it.
Is any one got any idea how to do it..

thanx in advance....
Feb 27 '07 #1
Share this Question
Share on Google+
19 Replies


100+
P: 170
Well a quick google revealed

echo date("m/d/Y",filemtime("filename.php"));

Format it how you like...
Feb 28 '07 #2

100+
P: 170
Or even better (I think) from the php manual

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // outputs e.g. 'Last modified: March 04 1998 20:43:59.'
  3. echo "Last modified: " . date ("F d Y H:i:s.", getlastmod());
  4. ?>
Feb 28 '07 #3

rishidadhich
P: 9
thanx Beary,
but problem is not solved yet.
I wanna write a script which will generate the last modified date of any outside url say www.example.com etc.
your code will generate last modified date of current file only.
Feb 28 '07 #4

100+
P: 170
thanx Beary,
but problem is not solved yet.
I wanna write a script which will generate the last modified date of any outside url say www.example.com etc.
your code will generate last modified date of current file only.

Aah. Sorry I didn't see that clearly. I found this page:

http://fundisom.com/phparadise/php/file_handling/remote_last_modified

which says it works. I tried it but the date kept saying January 1, 1970 for any file. But apparently it's exactly what you want. If I find something better I'll post. Otherwise, please let know that it works.
Feb 28 '07 #5

rishidadhich
P: 9
no its not working dear,
as you also noticed that its showing again and again January 1, 1970
b'coz its a unix timestamp, starting date of unix, so by default its showing that date.
yaa if u find anything please let me know..

thanx



Aah. Sorry I didn't see that clearly. I found this page:

http://fundisom.com/phparadise/php/file_handling/remote_last_modified

which says it works. I tried it but the date kept saying January 1, 1970 for any file. But apparently it's exactly what you want. If I find something better I'll post. Otherwise, please let know that it works.
Mar 1 '07 #6

100+
P: 170
no its not working dear,
dear????????????
Mar 1 '07 #7

rishidadhich
P: 9
ignore the words which u can't understand,
and try to be on the issue, which is how to get modified date of website.
well thanx for your efforts.
but i had solved the problem..

thanx again.
Mar 1 '07 #8

100+
P: 170
ignore the words which u can't understand,
and try to be on the issue, which is how to get modified date of website.
well thanx for your efforts.
but i had solved the problem..

thanx again.
So are you going to post your solution here? No-one else answered, which I assume means no-one else knew. Share the solution...

And by the way, perhaps next time you could leave the attitude at the door. You come to a forum to get help; stop acting like you're way above everyone else. I understood the words no problem; it was the tone that was off.

<mental note>ignore future posts from rishidadhich</mental note>
Mar 1 '07 #9

10K+
P: 13,264
Now guys that will be enough of that for now. No need to ignore each other's posts. I'm sure we all never intend to offend anyone. Unfortunately it just happens sometimes and whenever we dicover it we should be able to take back our offenses.

Now about the scipt

Expand|Select|Wrap|Line Numbers
  1.  
  2. Last modified: " . date ("F d Y H:i:s.", getlastmod());
  3.  
  4.  
I just wanted to know how one passes the name of the file to check the last modified date. I mean I understsood


Expand|Select|Wrap|Line Numbers
  1.  echo date("m/d/Y",filemtime("filename.php"));
  2.  
where I can see the filename passed as argument.
Mar 2 '07 #10

rishidadhich
P: 9
hi,
sorry if my words hurts any on.
ok leave it.........
now the code is..
Expand|Select|Wrap|Line Numbers
  1.                     $url = 'http://www.rediff.com/';
  2.  
  3.                     echo ("<pre>");
  4.                     $a= (get_headers($url,1));
  5.  
  6.                      $c =$a['Last-Modified'];
  7.                      echo ("<p>");
  8.                      print_r ($c);
  9.  
  10.  
It's just extracting last modified date from the header part.
If the website is not providing the last modified date then it wont work.
Mar 2 '07 #11

10K+
P: 13,264
Thanks a lot. Handy script.
Mar 2 '07 #12

zorgi
Expert 100+
P: 431
Thanks rishidadhich

It works if ['Last-Modified'] is within headers. I tested the script and found that 8 out of 10 times ['Last-Modified'] is not there. Any ideas anyone?
Mar 10 '08 #13

Markus
Expert 5K+
P: 6,050
Expand|Select|Wrap|Line Numbers
  1.  
  2. Last modified: " . date ("F d Y H:i:s.", getlastmod());
  3.  
  4.  
I just wanted to know how one passes the name of the file to check the last modified date.
you don't pass any arguments with getlastmod
getlastmod( void )
It returns the last mod of the current file. i.e. the file that this function is present in.

regards
Mar 10 '08 #14

P: 2
Thanks rishidadhich

It works if ['Last-Modified'] is within headers. I tested the script and found that 8 out of 10 times ['Last-Modified'] is not there. Any ideas anyone?
Any idea about this. For me 10 out of 10 times ['Last-Modified'] is not there.
Oct 22 '09 #15

dlite922
Expert 100+
P: 1,584
This is not possible to my knowledge. You send a request and the web server sends you a file. Those odd headers can't be counted on.

curious,

why do people want the modified date of remote websites?

what are you checking up on? How reliable is it when the website host moves or copies the file (without altering the contents) and the date is reset. The data the page gives you has not been "updated", even though if you were to get the new date.




Dan
Oct 22 '09 #16

P: 2
I have checked SEO posts where people say search engine spiders checks Last modified date header to know whether contents are updated or not. Even in tools like web ceo they have a field last updated. I never get this values for my sites.
Oct 23 '09 #17

P: 1
If you use firefox with firebug you can go to any page and insert this html and then click the button that gets inserted into the HTML.

Expand|Select|Wrap|Line Numbers
  1. <script 
  2.   type="text/JavaScript" 
  3.   language="JavaScript">
  4. <!-- 
  5. //
  6. // format date as dd-mmm-yy
  7. // example: 12-Jan-99
  8. //
  9. function date_ddmmmyy(date)
  10. {
  11.   var d = date.getDate();
  12.   var m = date.getMonth() + 1;
  13.   var y = date.getYear();
  14.  
  15.   // handle different year values 
  16.   // returned by IE and NS in 
  17.   // the year 2000.
  18.   if(y >= 2000)
  19.   {
  20.     y -= 2000;
  21.   }
  22.   if(y >= 100)
  23.   {
  24.     y -= 100;
  25.   }
  26.  
  27.   // could use splitString() here 
  28.   // but the following method is 
  29.   // more compatible
  30.   var mmm = 
  31.     ( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar':
  32.     ( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun':
  33.     ( 7==m)?'Jul':( 8==m)?'Aug':(9==m)?'Sep':
  34.     (10==m)?'Oct':(11==m)?'Nov':'Dec';
  35.  
  36.   return "" +
  37.     (d<10?"0"+d:d) + "-" +
  38.     mmm + "-" +
  39.     (y<10?"0"+y:y);
  40. }
  41.  
  42.  
  43. //
  44. // get last modified date of the 
  45. // current document.
  46. //
  47. function date_lastmodified()
  48. {
  49.   var lmd = document.lastModified;
  50.   var s   = "Unknown";
  51.   var d1;
  52.  
  53.   // check if we have a valid date
  54.   // before proceeding
  55.   if(0 != (d1=Date.parse(lmd)))
  56.   {
  57.     s = "" + date_ddmmmyy(new Date(d1));
  58.   }
  59.  
  60.   return s;
  61. }
  62.  
  63.  
  64. </script>
  65.  
  66. <input type="button" onclick="alert(date_lastmodified());" value="check" />
Jan 20 '10 #18

P: 1
hi,
sorry if my words hurts any on.
ok leave it.........
now the code is..
Expand|Select|Wrap|Line Numbers
  1.                     $url = 'http://www.rediff.com/';
  2.  
  3.                     echo ("<pre>");
  4.                     $a= (get_headers($url,1));
  5.  
  6.                      $c =$a['Last-Modified'];
  7.                      echo ("<p>");
  8.                      print_r ($c);
  9.  
  10.  
It's just extracting last modified date from the header part.
If the website is not providing the last modified date then it wont work.

Hey,
There are various sites which do not pass the last modified parameter in the header .How to fetch for those? EG-www.w3schools.com
May 7 '13 #19

Dormilich
Expert Mod 5K+
P: 8,639
How to fetch for those?
you donít. since you donít own the remote server, you have no access to the filesystem (which you would need for mtime) and hence you can only rely on what the server decides to send you as information.

besides that, what is the Last-Modified time of a script?
May 7 '13 #20

Post your reply

Sign in to post your reply or Sign up for a free account.