filemtime

i want to know the time of last modification on a file on the web
let's pretend is a website www.test.com/file.xml
on this server file.xml is modified every 45 minutes. I want to find the exactly time of the last modification. There is one more problem. Acces on this file si with a username and password.
Thanks
fradolcinoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RoonaanCommented:
You could try accessing through
filemtime('http://username:password@www.test.com/file.xml');

I think, however, that you will not be allowed to get the filemtime on remote files thru http.

-r-
0
fradolcinoAuthor Commented:
the problem is that the validation form is not a php form, is windows specific
0
RoonaanCommented:
Which validation form?

-r-
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

KennyTMCommented:
Hi.

You may, though not always works, check the "Last-Modified:" field of the response header when you send a HTTP request to the target page.

0
KennyTMCommented:
Implementation:

function filemtime_http ($url) {
  $a = parse_url ($url);
  if ($a['scheme'] == 'http') {
    $fp = fsockopen($a['host'], 80, $errno, $errstr, 30);
    if (!$fp)
      trigger_error("HTTP Error #$errno: $errstr.", E_USER_ERROR);
    else {
      fwrite ($fp, "HEAD $a[path] HTTP/1.1\r\nHost: $a[host]\r\nConnection: Close\r\n\r\n");
      $ss = substr(fgets($fp),0,-2);
      while (!feof($fp)) {
        $s = fgets($fp);
        if ( preg_match ('|^Last-Modified: (.+)$|', $s, $a) ) {
          fclose($fp);
          return $a[1];
        }
      }
      trigger_error("Cannot get last modified date. Server returned: $ss. Current date is returned instead.");
      fclose ($fp);
      return date('r');
    }
  } else
    trigger_error("Not a valid URL.", E_USER_ERROR);
}

echo filemtime_http ('http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/') . '<br />'; #Should return Fri, 29 Sep 2000 20:48:57 GMT
echo filemtime_http ('http://www.experts-exchange.com/Web/Web_Languages/PHP/PHP_Databases/Q_21816011.html') . '<br />'; #Should issue a notice and return the time now.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KennyTMCommented:
BTW, apply a strtotime() on the returned value to get the UNIX timestamp.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.