I would like to capture the modification date from a log file on the client machine in order to warn users (technical on an internal website) that they have not run updates for a given subsystem.

Is there a way to do this? I've done this sort of thing before, but reading the date on a file on the webserver. Getting the date from a file on the client seems to be an entirely different matter. Not sure if JavaScript would offer a solution, I'm not that up on JS.

You can use cURL for this, except after cURL execution you must add

$file_creation_time = curl_getinfo($curl, CURLINFO_FILETIME);

## use the file_creation_time for whatever you want

echo date("Y-m-d H:i:s", $file_creation_time);

another alternative is the PHP get_headers() function which can easily return the date. e.g.

$client_file_loc = 'some_remote_url';
$this_x = get_headers($client_file_loc, 1);

## this_x returns an array including the date which [1]

echo $this_x[1];
Member Avatar for diafol

Not sure the above will test files on a client machine. Not sure if you can do this. It's like snooping - so probably not possible. I may be wrong. I'd be aghast if a website I visited could read my local directories and files.

this will grab date from remote server file as long as public viewing is allowed. :)

<?php 


$client_file_loc = 'someRemoteLocation/file.txt';

echo (get_timestamp($client_file_loc));


function get_timestamp($url)
{

    $this_curl = curl_init($url);

    ## reference read from => http://curl.haxx.se/libcurl/c/CURLOPT_NOBODY.html
    curl_setopt($this_curl, CURLOPT_NOBODY, true);
    curl_setopt($this_curl, CURLOPT_RETURNTRANSFER, true);

    ## the magic will be taking place here and as reference => http://curl.haxx.se/libcurl/c/CURLOPT_FILETIME.html
    curl_setopt($this_curl, CURLOPT_FILETIME, true);

    $this_res = curl_exec($this_curl);

    if($this_res === false){

            die (curl_error($this_curl)); 

    }

    ## reference read from curlHaxx => http://curl.haxx.se/mail/lib-2005-12/0181.html
    $file_creation_time = curl_getinfo($this_curl, CURLINFO_FILETIME);

    if ($file_creation_time != -1) {

    return date("Y-m-d H:i:s", $file_creation_time);

    } 

    else{

            return false;
    }

}

this may not work on .asp, .php, .inc, .cgi file extensions. I have other means of doing it with those file extensions, but I think that is out of ethics to invade or rather intrude someone elses files.

here is a good test of the function above. Let say, we want to get the modification date of HII_PHP_SuperGlobals_Supersized_Trouble.pdf file

http://www.imperva.com/docs/HII_PHP_SuperGlobals_Supersized_Trouble.pdf

we can simple call our function above like this

$client_file_loc = 'http://www.imperva.com/docs/HII_PHP_SuperGlobals_Supersized_Trouble.pdf';

echo (get_timestamp($client_file_loc));

and the output will be the date the pdf file was modified

2013-09-03 18:41:37

pretty cool huh? :)

Hmm. If I ran batch script on the client machine to make the information available through a text file, environmental variable, etc., could that work?

If I ran batch script on the client machine

I totally agree with @difol! How dangerous it would be if you could run a batch script on a client machine! I'm sure this is definitely out of the question, as it's EXTREMELY unethical for websites to run programs on client systems, even on internal websites. Normally a system administrator for the network could handle this by manually programming a pure batch file (which could be done).

The only real way of saving/accessing data client side is by using cookies, which can be set to stay put for a good length of time and can hold a reasonable amount of data. But I think this could be difficult in your case.

In any sort of network I've seen, the administrators would just run command-line scripts over the network, and use network based tools to handle this. Correct me if I'm mistaken, but I don't think there's a way to do this in web-based languages.

Hmm. If I ran batch script on the client machine to make the information available through a text file, environmental variable, etc., could that work?

that will work on text, xml, tpl, html, phtml, htm files. HOWEVER, there is a big ethical issue here.

The best way to go around with the ethical issues is to notify your clients about this behind the server script. There must be a full disclosures between you and your client. It is not proper to just sneak behind them pulling their files.

Another option is to make it like how the wordpress checks on the version currently installed against the latest release. The idea is very similar, but the version checking is coming from the client machine and not the wordpress website. So, it is actually the website using the same technique outbound to the wordpress distribution site.

By the way, this will be my last response on this thread. I have given you what I thought will work out for you and I cannot write anymore codes that I considered covered by grey area and can define as an act of intrusion .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.