You are here

function lc_GetHeaders in Link checker 5

1 call to lc_GetHeaders()
lc_GetResponse in ./linkchecker.module

File

./linkchecker.module, line 472
This module periodically check html links referenced by drupal nodes Developed and maintained by Marek Tichy, marek@ecn.cz

Code

function lc_GetHeaders($url) {

  // Gets url ready to use
  $info = @parse_url($url);

  // Opens socket
  $fp = @fsockopen($info["host"], 80, $errno, $errstr, variable_get('linkchecker_socket_timeout', 3));

  // Makes sure the socket is open or returns false
  if (!$fp) {
    return false;
  }
  else {

    // Checks the path is not empty
    if (empty($info["path"])) {

      // If it is empty it fills it
      $info["path"] = "/";
    }
    $query = "";

    // Checks if there is a query string in the url
    if (isset($info["query"])) {

      // If there is a query string it adds a ? to the front of it
      $query = "?" . $info["query"] . "";
    }
    $info["path"] = str_replace(" ", "%20", $info["path"]);

    // Sets the headers to send
    $out = "HEAD " . $info["path"] . "" . $query . " HTTP/1.0\r\n";
    $out .= "Host: " . $info['host'] . "\r\n";
    $out .= "Connection: close \r\n";
    $out .= "Accept-language: en-us;q=0.7,en;q=0.3 \r\n";
    $out .= "Accept:   text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $out .= "Accept-charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7";
    $out .= "User-Agent:   Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.5) Gecko/20061201 Firefox/2.0.0.5 (Ubuntu-feisty) \r\n\r\n";
    d_("Headers sent: {$out}");

    // writes the headers out
    fwrite($fp, $out);
    $html = '';

    // Reads what gets sent back
    //  while ( !feof( $fp ) ) { - commented out, no need to read the whole thing
    $html .= fread($fp, 8192);

    //}

    // Closes socket
    fclose($fp);
  }
  return $html;
}