[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

How can i tell if a text file or HTML file is modified from the web.

Hi,

  How can i detect if a webpage is modified on the web via HTTP, I would like to write a program that will check a HTML/Text file to see if it has been updated or modified and display a popup message saying "web page updated". for example, If i create a text file "Blah.txt" and upload it to my webpage. everytime i edit "blah.txt" I want my program to popup a message saying update or webpage has been modified without downloading the file, Checking with be timer based of course.. More points will be awarded if requested. Souce code please.

Thanks,
Forton
0
Forton
Asked:
Forton
  • 4
  • 4
1 Solution
 
Ivanov_GCommented:

   On the server you can use for example PHP and filemtime($filename) which gives you the file modified time and store it in hidden field.

   From the client you should read this hidden field
0
 
mbprogrammerCommented:
in your request add this line :
If-Modified-Since: ' + RFC1123_Date(Your_Desired_DateTime) + ' GMT'
. the server will send the doc if it's newer than your given time.
0
 
mbprogrammerCommented:
here is the source code for RFC1123 function :

you cannot use Delphi own function because the date must be specified in  english and Delphi use the current language.

function RFC1123_Date(aDate : TDateTime) : String;
const
   StringWeekDay : String = 'MonTueWedThuFriSatSun';
   StringMonth   : String = 'JanFebMarAprMayJunJulAugSepOctNovDec';
var
   Year, Month, Day       : Word;
   Hour, Min,   Sec, MSec : Word;
   DayOfWeek              : Word;
begin
   DecodeDate(aDate, Year, Month, Day);
   DecodeTime(aDate, Hour, Min,   Sec, MSec);
   DayOfWeek := ((Trunc(aDate) - 2) mod 7);
   Result := Copy(StringWeekDay, 1 + DayOfWeek * 3, 3) + ', ' +
             Format('%2.2d %s %4.4d %2.2d:%2.2d:%2.2d',
                    [Day, Copy(StringMonth, 1 + 3 * (Month - 1), 3),
                     Year, Hour, Min, Sec]);
end;
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
FortonAuthor Commented:
Hi mbprogrammer,

 I'm a little confused on the "If-Modified-Since: ' + RFC1123_Date(Your_Desired_DateTime) + ' GMT'. the server will send the doc if it's newer than your given time" I want to ad this to a timmer but confused on the if modified syntex to excute the  request line, i know where your going with this and its a great idea. Thats what i want to do..

Forton.
0
 
mbprogrammerCommented:
you shoud add that line in your request string and then send your request to server
0
 
FortonAuthor Commented:
Hi,
 
 I still cannot make any sense of how to use the commandline or how its suppose to get the date by (Your_Desired_DateTime) or how to get my program to tell me if its modified or not, could you make a demo app, posting it here or emailing it to my email hyperon@eudoramail.com.
I will also give more points if needed.

Thanks,
Forton.
0
 
mbprogrammerCommented:
Ok lets start from first :
 Your program want to know whether any updates after 2004/04/19
 for the file http://www.mypage.com/updates/myfile.txt 
 is available or not.
 It should send a request to web server.
 for doing this, you should do one of bellow methods :

 1 :
    you should send a http request like bellow
    (via http components such as ICS or Indy) :

     "GET /updates/myfile.txt HTTP/1.1
     Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
     Connection: Keep-Alive
     Accept-Language: en
     User-Agent: Mozilla/3.0 (compatible)
     Host:www.mypage.com
     If-Modified-Since: Mon, 19 Apr 2004 00:00:00 GMT"

   which tells web server to send the file
   if the file is newer than 2004/04/19.
   and if your web server is Http ver 1.1 then you can specify
   a range for your file for resuming after a breakdownload or .....
   it's like this :
     'Range: bytes=0-1'
   the first integer indicates the start position and the seccond is
   length of data you want.if you dont specify the seccond integer
   the server will send it from start position you specified to end.
   
   for creating this time --> 'Mon, 19 Apr 2004 00:00:00 GMT'
   from this --> 2004/04/19 ,you should use RFC1123 function
    plus a GMT string after the result of the function.

 2:
   you can upload a file in your server which contains information
   about your application updates and other things
   (for example what's new and ...).Then your program will download
   that file and process it's information for any info it needs.
0
 
FortonAuthor Commented:
HI

 I have a text file on a server, i can get the file no problem with my program, using http get, i cannot figure the excute commandline you have posted. I keep getting date invalid while trying to ecute your code.


Forton.
0
 
FortonAuthor Commented:
ok i fixed it, i screwed up on a few things but fixed now. Thank you so much..


Forton.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now