We help IT Professionals succeed at work.

perl: last modified

rw263
rw263 asked
on
Medium Priority
304 Views
Last Modified: 2013-12-25
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! :-)
Comment
Watch Question

CERTIFIED EXPERT

Commented:
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.

Author

Commented:
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?
CERTIFIED EXPERT

Commented:
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.
CERTIFIED EXPERT

Commented:
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.

Commented:
#!/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";

Author

Commented:
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?

Commented:
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
CERTIFIED EXPERT

Commented:
.. and if JavaScript is disabled ..
CERTIFIED EXPERT

Commented:
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,

Author

Commented:
nothing found yet.
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
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.
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
never figured this one out.
CERTIFIED EXPERT

Commented:
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   http://www.experts-exchange.com/jsp/qShow.jsp?ta=cgi&qid=20186333   09/22/01  
CGI   http://www.experts-exchange.com/jsp/qShow.jsp?ta=cgi&qid=20191896   10/07/01  
Microsoft Outlook   http://www.experts-exchange.com/jsp/qShow.jsp?ta=msoutlook&qid=20257387   01/20/02  
Windows 98   http://www.experts-exchange.com/jsp/qShow.jsp?ta=win98&qid=20248556   12/22/01  
Windows 98   http://www.experts-exchange.com/jsp/qShow.jsp?ta=win98&qid=20249065   12/26/01  
Windows 98   http://www.experts-exchange.com/jsp/qShow.jsp?ta=win98&qid=20250894   01/02/02  
Windows 98   http://www.experts-exchange.com/jsp/qShow.jsp?ta=win98&qid=20251675   01/04/02  
Windows 98   http://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.

Author

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

Author

Commented:
I am being asked to close open questions and since no one has answered this in a bit, I'm going to delete it?
CERTIFIED EXPERT
Commented:
"can't be done" is a answer to your question

But according to RFC 2616 your browser might send a request header with
     If-Modified-Since
     If-Unmodified-Since
and check this way the modification time.
And according the same RFC you might get in your response
     Last-Modified
but that entitity is optional (see RFC 2616), so see my 1'st sentence above.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.