Link to home
Start Free TrialLog in
Avatar of rw263
rw263

asked on

perl: last modified

I am looking for a way to get when a webpage was last modified on any server. I believe this informatin is in the mime http header, but I don't know how to access this infromation. I am looking for something like:
  getLastModifiedDate('http://path/to/file.html');

HELP!! THANKS! :-)
Avatar of periwinkle
periwinkle
Flag of United States of America image

Are you looking to write a program to find out the date on an arbitrary file on the server, or would you like to find out the date in the current file?

If you have server side includes enabled, you could simply use something like:

<!--#echo var="LAST_MODIFIED" -->

in the source code, and it will echo the date that the file was last modified.

If you wish to show the date another  file was last modified through a cgi script, you'd use something like this in perl:

($READTIME, $WRITETIME) = (stat($filename))[8,9];

This will set $READTIME to the timestamp that a file was last accessed, and $WRITETIME to the timestamp of when it was last modified.
Avatar of rw263
rw263

ASKER

periwinkle  --

As I stated in my question, it is on a server I don't have access to. I want to see when a webpage was last updated. Server Side Includes are helpful if the file is on a server you have access to, the same with $filename. What I would like is to find out when a html page that I provide the servername, path, filename, (the URL) and get the last time it was modified. Hopefully this clears it up a little?
Your meaning wasn't clear in the original wording of the question, and I misunderstood what you were trying to do.  I don't have an answer for what you are trying to do - sorry.
simple answer: you can't
long answer: it might be possible if the maintainer of the page writes appropriate information into the .html file itself. This is most likely done in the <META ...> tags.
#!/usr/bin/perl

use LWP::Simple;

$url = "http://server/file.htm";

($content_type, $document_length, $modified_time, $expires, $server) = head($url);
($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime($modified_time))[0,1,2,3,4,5,6];
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$year += 1900;
$mon++;

print "Content-type: text/html\n\n";
print "$mday/$mon/$year, $time";
Avatar of rw263

ASKER

aryumin  --

this didn't work. When I tried to print out the variables that got sent from head($url), look at what I get:

content_type: text/html
document_length:
modified_timet: Apache/1.3.12 (Unix) mod_layout/2.10.6 mod_ssl/2.6.5 OpenSSL/0.9.5
expires:
sever:

Any ideas?
The Last-modified HTTP header is not always available...
The MS IIS, for example, doesn't send this header for "active" content (ASP, pages with SSI, scripts, etc.)
Do you absolutely want to handle the headers yourself? Could you just  write it into the body at the browser end with javascript:

http://www.xs4all.nl/~ppk/js/lastmod.html
.. and if JavaScript is disabled ..
rw263,

Did you get the solution you were looking for?

If so, please delete this question & free up your points, or award the points to the answer you found most useful.

Thanks,
Avatar of rw263

ASKER

nothing found yet.
rw263,

"..nothing found yet. ..."

":..I am looking for a way to get when a webpage was last modified on any server...."

Are there some sample URL's that you can post here?

i can take those URL's & see if i can get the last modified date of those pages.

Let me know.
Avatar of rw263

ASKER

well the urls I am looking for are on secure servers, you need a name/pwd, and I would not feel safe giving out that info. Sorry.
rw263

"..Sorry.."

I can understand your concern.

Without a URL, i am pretty much shooting in the dark. Seems like there is very little i can provide you in terms of a solution.

Hope you get a working solution soon.

Avatar of rw263

ASKER

never figured this one out.
rw263,

Including the 4 questions that you have opened this month, you have 4 other questions open.

Please take some time to close the open questions.

EE userid rw263
Total questions asked 46 (100%)
Open questions 8 (17.39%)
       
Topic Area              URL              Date              
CGI   https://www.experts-exchange.com/jsp/qShow.jsp?ta=cgi&qid=20186333   09/22/01  
CGI   https://www.experts-exchange.com/jsp/qShow.jsp?ta=cgi&qid=20191896   10/07/01  
Microsoft Outlook   https://www.experts-exchange.com/jsp/qShow.jsp?ta=msoutlook&qid=20257387   01/20/02  
Windows 98   https://www.experts-exchange.com/jsp/qShow.jsp?ta=win98&qid=20248556   12/22/01  
Windows 98   https://www.experts-exchange.com/jsp/qShow.jsp?ta=win98&qid=20249065   12/26/01  
Windows 98   https://www.experts-exchange.com/jsp/qShow.jsp?ta=win98&qid=20250894   01/02/02  
Windows 98   https://www.experts-exchange.com/jsp/qShow.jsp?ta=win98&qid=20251675   01/04/02  
Windows 98   https://www.experts-exchange.com/jsp/qShow.jsp?ta=win98&qid=20251676   01/04/02  

You help to close this questions will be highly appreciated.

Thanks.
Avatar of rw263

ASKER

I am being asked to close open questions and since no one has answered this in a bit, I'm going to delete it?
Avatar of rw263

ASKER

I am being asked to close open questions and since no one has answered this in a bit, I'm going to delete it?
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial