Forum Moderators: coopster

Message Too Old, No Replies

Showing modified dates on external files

Doesn't seem to work

         

Hester

12:44 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would like to display the last modified date of a file on another server. My script works for local files (on the same server as the script).

Here is my code so far:

$url1 = "http:// ...external URL... ";

$filemod = filemtime($url1);

echo date("j F Y", $filemod);

I have tried opening the file first and including it. That works, but not the above script. Am I barking up the wrong tree?

ShawnR

1:40 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can't use filemtime on remote files. Generally the php functions you can use on remote files are those which take a filehandle argument (that is returned from the fopen), not those which take a string path argument.

I can't think of how you could do it other than running a script at the operating system level.

Shawn

Hester

1:57 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Would another language like Perl or JavaScript be able to do it?

ShawnR

2:07 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Javascript can't do it. Perl could do it in the same sense that php could do it: exec() a script at the operating system level (in perl, use the backtick). What I mean by that is that you could write a script which initiates a ftp or telnet session, use an ftp command to retrieve the file's timestamp, then close that ftp session... Others might have more elegant suggestions, but that is all I can think of.

Shawn

Hester

2:26 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But that would require FTP access being allowed. I want to link to several sites I don't own, but provide the date when they were last modified. Like you can do by pinging certain weblogs. I could then write a script so it gave the number of days since the last update. Eg: "Updated 2 days ago".

I guess it ain't possible. :(

ShawnR

2:48 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All I can think o is to poll them periodically, calculate a checksum, and keep track of when the checksum changes. Others with more knowledge might be able to offer a better solution.

Take care, though! If you don't have access to the sites, it might be better to request it, and let the site owners know what you are doing. The reason is that you are diverting traffic away from them, potentially. Visitors might look at your site and only visit theirs when there is a change, whereas without your site, the visitors might go have a look at theirs more frequently, to check for updates. So you might get into trouble with Intellectual Property issues, and you may not win favour with the sites you are monitoring. If that happens they'll start playing silly games to invalidate your results (make the checksums change when there has not been any real change to the site, or show your process an old site and real visitors the new site, so it looks like your site isn't working).

Shawn

Hester

3:09 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The reason is that you are diverting traffic away from them, potentially.

The exact opposite of what I was intending!

Take a look at the way this site displays links down the left with the date last updated underneath. I thought it was a great idea.

[edited by: jatar_k at 4:27 pm (utc) on May 15, 2003]
[edit reason] no urls thanks [/edit]

jdMorgan

3:15 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm no coding genius, but is it possible, using LWPsimple or some such library, to do an HTTP HEAD request on the remote file and then extract the last-modified-date from the response manually?

Jim

mavherick

3:20 pm on May 15, 2003 (gmt 0)

10+ Year Member



jdMorgan is absolutely right, just take a look at the last comment on this page [php.net] of the php manual.

mavherick

ShawnR

3:37 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I said "others with more knowledge might be able to offer a better solution", and I was right!

The exact opposite of what I was intending!

Understood. Just suggesting you establish rapport with the owners of the site, so there is no misunderstanding, and they don't think you are a bad spider or a 'site-watch' utility.

Shawn