home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / sharewar / gdidbpro / data1.cab / Example_Files / projects / default / linkcheck.scp < prev    next >
Text File  |  2000-05-26  |  2KB  |  85 lines

  1. ##########################################################
  2. # GDIdb demo script (c) 1998 Global Data Industries
  3. #
  4. # This script is designed to check web URL's held in a
  5. # database. GDIdb will attempt to retrieve the status of
  6. # each URL, if the server responds with a code of 404
  7. # (404=http 'Object not found' code) then GDIdb will
  8. # delete the database record that contains the URL.
  9. ##########################################################
  10.  
  11.  
  12.  
  13.  
  14. ##########################################################
  15. # this database contains our table of links
  16.  
  17. &datasource("Driver={Microsoft Access Driver (*.mdb)};DBQ=examples.mdb")
  18.  
  19.  
  20.  
  21.  
  22. ##########################################################
  23. # define variables used in script
  24.  
  25. &defvar(?content?,?header?,?error?,?errorcode?)
  26.  
  27.  
  28. ##########################################################
  29. # if you don't want GDIdb to dial your Internet connection
  30. # before checking the URL's, change the following line
  31. # to &dialup(FALSE)
  32.  
  33. &dialup(TRUE)
  34. {
  35.     &getdata("SELECT * FROM tblURLs")
  36.     {
  37.         # get HTTP header from web server
  38.         &assign(?error?,0)
  39.         &http(?header?,?content?,"?URL?","HEAD")
  40.         
  41.         # If server didn't respond
  42.         &if(?error?)
  43.         {
  44.             # if you don't want links removed where the server didn't respond
  45.             # (the server could be temporarily down), remove the following line
  46.             &removelink
  47.             
  48.             &continue
  49.         }
  50.         
  51.         # if server responds with code 404 (object not found), delete link
  52.         &split(?c?,"?header?")
  53.         &if(?c[2]?==404)
  54.         {
  55.             &removelink
  56.         }
  57.         &arraydelete(?c?)
  58.     }
  59. }
  60.  
  61.  
  62.  
  63. ##########################################################
  64. # GDIdb will run this subroutine when a bad URL is found.
  65.  
  66. &defsub("removelink")
  67. {
  68.     &print("Deleting ?URL?")
  69.     &sqlnr("DELETE FROM tblURLs  WHERE URL='?URL?'")
  70. }
  71.  
  72.  
  73.  
  74. ##########################################################
  75. # catch HTTP errors
  76.  
  77. &defsub("on_error")
  78. {
  79.     &geterror(?errorcode?,FALSE)
  80.     &if((?errorcode?==119)||(?errorcode?==106))
  81.     {
  82.         &assign(?error?,1)
  83.         &ignore
  84.     }
  85. }