Getting a URL's publish/change date programatically
Moderator: General Moderators
-
eastsidedev
- Forum Newbie
- Posts: 6
- Joined: Tue Feb 10, 2009 2:02 pm
Getting a URL's publish/change date programatically
I am starting to work with web page, and I need to programatically get a page's creation date and/or modification date. Would anyone have a code fragment (or a pointer) that can do that.
Regards,
Joseph
Regards,
Joseph
Re: Getting a URL's publish/change date programatically
Code: Select all
filemtime('/path/to/file');
-
eastsidedev
- Forum Newbie
- Posts: 6
- Joined: Tue Feb 10, 2009 2:02 pm
Re: Getting a URL's publish/change date programatically
This just tells me how to get a file date/time, not how I can get a web page's creation date/time. Note that all I have is the URLs.astions wrote:Code: Select all
filemtime('/path/to/file');
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Getting a URL's publish/change date programatically
Can you be specifc in your meaning of a webpage? Does "webpage" mean individual files on a domain, or the domain itself?
http://ca.php.net/manual/en/function.fi ... .php#73747 can look up the last modified of remote files
http://ca.php.net/manual/en/function.fi ... .php#73747 can look up the last modified of remote files
-
eastsidedev
- Forum Newbie
- Posts: 6
- Joined: Tue Feb 10, 2009 2:02 pm
Re: Getting a URL's publish/change date programatically
Here's what I mean. I have a bunch of URLS:John Cartwright wrote:Can you be specifc in your meaning of a webpage? Does "webpage" mean individual files on a domain, or the domain itself?
http://ca.php.net/manual/en/function.fi ... .php#73747 can look up the last modified of remote files
http://www.microsoft.com/security/default.mspx
http://www.cisco.com/en/US/products/hw/ ... index.html
etc.....
and I would like to know when these pages were created or modified.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Getting a URL's publish/change date programatically
Did you look at the link I gave you?
-
eastsidedev
- Forum Newbie
- Posts: 6
- Joined: Tue Feb 10, 2009 2:02 pm
Re: Getting a URL's publish/change date programatically
Oops. Need new glasses, for some reason I thought this was part of your signature. I will try the link. Thx.John Cartwright wrote:Did you look at the link I gave you?
-
eastsidedev
- Forum Newbie
- Posts: 6
- Joined: Tue Feb 10, 2009 2:02 pm
Re: Getting a URL's publish/change date programatically
I looked at it and tried it. It does not work, because there is no file to open if I don't know the exact default file name (index.php, index.html, default.html, etc.).John Cartwright wrote:Did you look at the link I gave you?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Getting a URL's publish/change date programatically
You do not need to specify an actual file, only an http address. Although, thinking about it more it is up to the server to disclose the last modified header. In fact, when I tested it on this forums they did not report the last modified date. You can examine the headers to see for youself.
Code: Select all
function GetRemoteLastModified( $uri )
{
// default
$unixtime = 0;
$fp = fopen( $uri, "r" );
if( !$fp ) {return;}
$MetaData = stream_get_meta_data( $fp );
foreach( $MetaData['wrapper_data'] as $response )
{
// case: redirection
if( substr( strtolower($response), 0, 10 ) == 'location: ' )
{
$newUri = substr( $response, 10 );
fclose( $fp );
return GetRemoteLastModified( $newUri );
}
// case: last-modified
elseif( substr( strtolower($response), 0, 15 ) == 'last-modified: ' )
{
echo $response;
exit();
$unixtime = strtotime( substr($response, 15) );
break;
}
}
fclose( $fp );
return $unixtime;
}
echo GetRemoteLastModified('http://forums.devnetwork.net');-
eastsidedev
- Forum Newbie
- Posts: 6
- Joined: Tue Feb 10, 2009 2:02 pm
Re: Getting a URL's publish/change date programatically
Yes, I kept getting a 0.
John Cartwright wrote:You do not need to specify an actual file, only an http address. Although, thinking about it more it is up to the server to disclose the last modified header. In fact, when I tested it on this forums they did not report the last modified date. You can examine the headers to see for youself.
Code: Select all
function GetRemoteLastModified( $uri ) { // default $unixtime = 0; $fp = fopen( $uri, "r" ); if( !$fp ) {return;} $MetaData = stream_get_meta_data( $fp ); foreach( $MetaData['wrapper_data'] as $response ) { // case: redirection if( substr( strtolower($response), 0, 10 ) == 'location: ' ) { $newUri = substr( $response, 10 ); fclose( $fp ); return GetRemoteLastModified( $newUri ); } // case: last-modified elseif( substr( strtolower($response), 0, 15 ) == 'last-modified: ' ) { echo $response; exit(); $unixtime = strtotime( substr($response, 15) ); break; } } fclose( $fp ); return $unixtime; } echo GetRemoteLastModified('http://forums.devnetwork.net');