edainworks.com :: VGR :: remotely testing URIs (URLs).

Run :
3 links in input
link 1 'http://www.netscape.com' is OK
link 2 'http://www.badlink.zob' is KO
link 3 'http://www.experts-exchange.com' is KO
2 bad links found
bad link 'http://www.badlink.zob' (index=0)
bad link 'http://www.experts-exchange.com' (index=1)

Code :
function CheckURI($parurl) { //VGR18032003
  // inits
  $result=TRUE;
  // try to get URI
  $filename = "$parurl";
  $tobec=TRUE;
  $fd = @fopen ($filename,'r');
  if ($fd) { // si page trouvée
    while ((!feof ($fd))and($tobec)) {
      $ligne= fgets($fd, 4096);
      if (!(strpos($ligne,'[404] Not Found')===false)) $tobec=FALSE; // stop as soon as this is encountered
      $contents []=$ligne;
    } // while lecture bloquante
    fclose ($fd);
    if ($tobec) { // file entirely read OK (note that we could stop after X first lines, the '404' message is not at the 345th line...
      // nothing, result is TRUE already
      // this block is in case you want to log anything like "last correct date where found the URI was OK"
    } else { // we stopped before the end : 404 found
      $result=FALSE;
    }
  } else { // page not found
    $result=FALSE;
  } // if page trouvée ou non
  return $result;
} // CheckURI Boolean Function

Vincent Graux (VGR) for European Experts Exchange and Edaìn Works  back to list of test scripts
Last update 2024-05-13 15:35:48