NYCPHP Meetup

NYPHP.org

[nycphp-talk] Accessing a file in another web server

Dan Cech dcech at phpwerx.net
Thu Jan 4 20:01:27 EST 2007


Néstor wrote:
> OK guys,
> 
> Just in case you are interested, I found a faster solution than fopen()
> 
> --------------------------------------------------------------------------------------------------

I've corrected some things for you:

<?
function url_exists($strURL) {
   $resURL = curl_init();
   curl_setopt($resURL, CURLOPT_URL, $strURL);
   // return the result instead of echoing it
   curl_setopt($resURL, CURLOPT_RETURNTRANSFER, 1);
   // time out after 5 seconds of no response
   curl_setopt($resURL, CURLOPT_TIMEOUT, 5);

   $result = curl_exec ($resURL);
   if ($result === false) {
      curl_close($resURL);
      return false;
   }

   $intReturnCode = curl_getinfo($resURL, CURLINFO_HTTP_CODE);
   curl_close ($resURL);

   if ($intReturnCode != 200 && $intReturnCode != 302 && $intReturnCode !=
304) {
      return false;
   }

   return true;
}

//Usage Example :
If(url_exists("http://www.weberdev.com/addexample.php3")) {
   Echo"URL Exists";
}Else{
   Echo"URL doesnot exist";
}
?>



More information about the talk mailing list