[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

filemtime

Posted on 2006-04-17
6
Medium Priority
?
338 Views
Last Modified: 2013-12-12
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
0
Comment
Question by:fradolcino
  • 3
  • 2
6 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 16468111
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
 

Author Comment

by:fradolcino
ID: 16468144
the problem is that the validation form is not a php form, is windows specific
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 16468178
Which validation form?

-r-
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Expert Comment

by:KennyTM
ID: 16470319
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
 
LVL 8

Accepted Solution

by:
KennyTM earned 440 total points
ID: 16470685
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
 
LVL 8

Expert Comment

by:KennyTM
ID: 16470795
BTW, apply a strtotime() on the returned value to get the UNIX timestamp.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month20 days, 5 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question