SEO Forums















                                          
User   Password   remember     (register)  ?

How to use curl to retrieve an url ?


Back to php.


guest-curler    (2009-04-23)
 
How to use curl to retrieve an url ?

Hi all,

Here is a very simple function to retrieve the content from an url, it uses the CURL function if it does exist only, otherwise the file_get_contents() function is used instead. Useful

<?

function retrieve_url($url)
{

if (substr($url, 0, 7) != 'http://')  $url = 'ht*p://'.$url;


// if curl not installed
if (!function_exists('curl_init'))
{
    return file_get_contents($url);
}

else
{
    // new curl resource
    $ch = curl_init();

    // set url where to download content
    curl_setopt($ch, CURLOPT_URL, $url);

    // set referrer
    curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com/");

    // set user agent
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");

    // remove header or not : 0 = yes, 1 = no
    curl_setopt($ch, CURLOPT_HEADER, 0);

    // curl may return or print the data : true = return, false = print
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // timeout in seconds
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

    // get the content from url
    $content = curl_exec($ch);

    // close the curl resource
    curl_close($ch);

    return $content;

}
}


?>



ficgs
Suggestions

 cURL and libcurl
curl.haxx.se/

 cURL - Wikipedia, the free encyclopedia
en.wikipedia.org/wiki/CURL

 How to Use Curl Attributes | eHow.com
www.ehow.com/how_2036713_use-curl-attributes.html

  How To Use cURL (in PHP) For Authentication And SSL Communication
blog.taragana.com/index.php/archive/how-to-use-curl-in-php-for-authenticati

 Ibuildings - Ibuildings blogs > Multithreading in PHP with CURL
www.ibuildings.com/blog/archives/811-Multithreading-in-PHP-with-CURL.html

 YUI Library Examples: Connection Manager: Retrieving a Yahoo! Weather RSS Feed
developer.yahoo.com/yui/examples/connection/weather.html

 Opening the web and retrieving all the goodies (Yahoo! Developer Network Blog)
developer.yahoo.net/blog/archives/2008/12/opening_the_web.html



ficgs
More suggestions

This is a collaborative page, you may change the order of these suggestions by registering, then clicking the icons before the titles.


 Can I use cURL for a form with GET method? [Archive] - PHPBuilder.com
www.phpbuilder.com/board/archive/index.php/t-10330616.html

 DevNetwork Forums • Information
forums.devnetwork.net/viewtopic.php?f=14&t=86696

 Bash: curl and redirected url
www.experts-exchange.com/Programming/Languages/Scripting/Shell/bash/Q_24036

 EmacsWiki: Oddmuse Mode
www.emacswiki.org/emacs/OddmuseMode

 Class: Curl::Easy
curb.rubyforge.org/classes/Curl/Easy.html

 Encoding problem using CURL to retrieve XML - Dev Shed
forums.devshed.com/php-development-5/encoding-problem-using-curl-to-retriev

 Fetching remote content with curl | - [ t o i c . o r g ] -
toic.org/2008/10/08/fetching-remote-content-with-curl/

 cURL - Frequently Asked Questions
curl.netmirror.org/docs/faq.html

 PHP: CURL - Manual
php.chinaunix.net/manual/zh/ref.curl.php

 Getting Started with the Twitter API
www.devx.com/webdev/Article/40359/1954

 Practical PHP Programming:Your first Curl scripts - IpbWiki
www.ipbwiki.com/Practical_PHP_Programming:Your_first_Curl_scripts

  Reading a Remote File Using PHP - PHP MySQL Tutorial
www.php-mysql-tutorial.com/wikis/php-tutorial/reading-a-remote-file-using-p

  Curl and SSL help - error during istallation - Zen Cart Support
www.zen-cart.com/forum/showthread.php?t=97000

 'Re: RE: Re: Retrieving XML file through an HTTP url requiring athentication' - MARC
marc.info/?l=curl-and-php&m=107342301231320&w=2

 PHP: CURL, Client URL Library Functions - Manual
theserverpages.com/php/manual/en/ref.curl.php

  Use curl to find redirect url of http://www.disney.com - Usenet Forums
www.usenet-forums.com/php-language/23977-use-curl-find-redirect-url-http-ww

  Using CURL to get the HTTP status code of a URL - bytes
bytes.com/groups/php/5230-using-curl-get-http-status-code-url

  piping a url to wget or curl? - Shell Programming and Scripting - The UNIX and Linux Forums
www.unix.com/shell-programming-scripting/27969-piping-url-wget-curl.html

 Tutorial : Display no.of Readers using Feedburner API and PHP (curl) | Vision Master Designs
visionmasterdesigns.com/tutoral-display-noof-rss-readers-using-feedburner-a

  PHP : Function Reference : CURL, Client URL Library Functions : curl_exec PHP Examples Tutorials References
www.navioo.com/php/docs/function.curl-exec.php

 6 essential cURL commands for daily use : CodeDiesel
www.codediesel.com/tools/6-essential-curl-commands/

 Get url via http-proxy in php+curl | PHP | Shopzz Blog - Just another programmer weblog
www.shopzz.org/2007/07/21/get-url-via-http-proxy-in-phpcurl.shtml

 How to Use CURL With PHP | Code and Coffee
www.codeandcoffee.com/2006/07/how-to-use-curl-with-php/

 Use curl from PHP - processing response headers
it.toolbox.com/wiki/index.php/Use_curl_from_PHP_-_processing_response_heade

 load() Function for PHP - Fetch URL Content
www.bin-co.com/php/scripts/load/

 PHP :: How To Use CUrl
www.bigresource.com/PHP-How-to-use-CUrl-C2rnVppZ.html

 Practical PHP Programming | TuxRadar
www.tuxradar.com/practicalphp/15/10/2

  Error when retrieving file contents - CodingForums.com
codingforums.com/showthread.php?t=161616

 Rick's spam digest :: Spamstopper's notebook -- curl
www.rickconner.net/spamweb/tools-curl.html



Response  
  Smilies

Guest name   (optional)       Register for more options.



Trackbacks : If you talked about this article in your blog or website, you may instantly get a backlink 
  There's no trackback at the moment.









 

FICGS message




SEO forums and chat - Search engines optimization



 

March 20, 2010

 

Buttons: Facebook, Twitter, MySpace, Google, Technorati, Yahoo buzz... Ficgs Facebook Myspace Twitter Google Technorati Stumble upon Delicious Digg Yahoo buzz Wikio Furl Reddit Linkedin Squidoo Newsvine Yahoo My Web Blogmarks Comments Blinklist Email

You comment I follow : Links included in comments will be "dofollow" if your post is not an obvious spam, comments are published instantly.


Write upside down to your friends !
(works with MySpace, Twitter, Facebook, Youtube, MSN, Hi5, Bebo, Yahoo...)







FICGS is also a Free Internet Correspondence Games Server.

Here you can play Chess, Go & Poker Texas Holdem online for free in rated class tournaments and a unique world championship.

Free Internet Chess & Go Server


Feel free to link to FICGS :