Reputation: 608
I've been struggling for hours now and can't seem to find myself an good answer.
I'm making an script to retrieve modification dates of several files on external servers. Since i'm currently using curl for retrieving these data, it will in my case only show the data of all the files i need to request accept a .php file..
Little script of what i use..
function modified($url){
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FILETIME, true);
$result = curl_exec($curl);
$timestamp = curl_getinfo($curl, CURLINFO_FILETIME);
if ($timestamp != -1):
echo date("Y-m-d H:i:s", $timestamp);
else:
echo 'No timestamp found';
endif;
}
echo modified('http://myurl.com/');
Am i doing something wrong or is retrieving .php files in this case out of possibility.
Upvotes: 0
Views: 1286
Reputation: 24116
What you are trying to do is not possible.
A way around this is to write another PHP file, which is able to check the filemtime
of given php file on the server.
filemtime.php
<?php
// Get Requested File Name
$filename = isset($_GET['filename']) ? $_GET['filename'] : '';
// Return Result
if (file_exists($filename)) {
echo filemtime($filename);
} else {
echo 0;
}
?>
Then usage will be like this:
<?php
// Load last time index.php was modified on the server
$filemtime = intval(file_get_contents('http://yourdomain.com/filemtime.php?filename=index.php'));
// Parse Result
echo 'index.php was modified on '. date('d/m/Y H:i:s a', $filemtime);
?>
Upvotes: 1