Should add some URL verification to make sure that URL actually exists, in addition to being well formed...

    // if curl exists do a request to see if the url exists out there in cyperspace
    $status = array(); // http status
    if (function_exists('curl_init') && LINK_CURL_CHECK) {
      $ch = curl_init();

      // set URL and other appropriate options
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 10 seconds
      curl_setopt($ch, CURLOPT_HEADER, TRUE);
      curl_setopt($ch, CURLOPT_NOBODY, TRUE);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
      
      $link_exists = curl_exec($ch);
      preg_match('/HTTP\/.* ([0-9]+) .*/', $link_exists, $status);    
      curl_close($ch);
    }
    else {
      $link_exists = true;
      $status[1] = 1;
    }
    if (!$link_exists || $status[1] == 404) {
      form_set_error('url', t('The URL entered appears to be invalid. Please try a different URL.'));
    }  

Comments

m3avrck’s picture

Status: Active » Closed (duplicate)