Como saber se uma url existe, utilizando cURL.

Olá, aqui vai um exemplo simples a rapido para saber se um url existe.

<?php
/**
* @author marcelo toscano
*/
$tmpUrl ="http://www.toscano.com.br";
$handler =curl_init();
curl_setopt($handler, CURLOPT_URL,$tmpUrl); // define a url a ser consultada</span>
curl_setopt($handler, CURLOPT_HEADER, false); // true para retornar o cabaçalho
curl_setopt($handler, CURLOPT_NOBODY, true); // true para não retorna o body
$retorno=curl_exec($handler); //retorna true ou false
curl_close($handler);

if($retorno){
echo "ok a url $tmpUrl existe\n"</span>;
}
else{
echo "ooops #fail";
}?>

No related posts.

No Responses to “Como saber se uma url existe, utilizando cURL.”

Trackbacks/Pingbacks

  1. Tweets that mention Como saber se uma url existe, utilizando cURL. « PHP Rocks! -- Topsy.com - [...] This post was mentioned on Twitter by Marcelo Toscano and alexandretaz, phprocks. phprocks said: novo post no @phprocks http://bit.ly/55HKI6 ...

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Warning: Invalid argument supplied for foreach() in /home/phprocks/phprocks.com.br/wp-content/plugins/socialize-it/inc/SocializeIt.php on line 65