0

I have a PHP on HTTPS page (eg. https://www.example1.com/page1.php) in which I would like to obtain the update date of a second page from a third domain always in HTTPS (eg. https://www.example.com/sitemap.xml).

I tried with the following code, however I always get "was last modified on 01 Jan 1970 01:00:00":

<?php

//The path to the file that you want to get
//the last modified time and date of.
$file = 'https://www.example.com/sitemap.xml';

//Get the last modified time using the filemtime function.
//This function will return a Unix timestamp.
$lastModifiedTimestamp = filemtime($file);

//Convert the timestamp into a human-readable format
//and print it out.
$lastModifiedDatetime = date("d M Y H:i:s", $lastModifiedTimestamp);

echo "$file was last modified on $lastModifiedDatetime";
?>

Could some kind person please help me in finding a solution or alternative?

  • I suspect `$lastModifiedTimestamp` may be null because you can't read the timestamp of a file through http - by the way, this has nothing to do with javascript, so please don't tag spam – Jaromanda X Oct 05 '20 at 06:19
  • Are there no alternatives? I would like to point out that the post is not similar to the linked one, so closing it is mean. – Gabriele C. Oct 05 '20 at 06:42
  • look at trante's answer https://stackoverflow.com/a/22577636/5053002 – Jaromanda X Oct 05 '20 at 06:43

0 Answers0