CURL – Client Url Library for PHP

CURL is a very essential library in PHP. In some website, like if you have an account in there you’ll see, there is an option to import contacts from yahoo, gmail or hotmail. If you put your account name and password they will import the contacts from your account.

Do you know how’ll they do so. Yeah, there may be many libraries. But this type of work could be done using the CURL libary. I’ve done this type of works 2 months ago. So, I think I should share it to novice or intermediate PHP developer.

What is CURL?

  1. It is a library created by Daniel Stenberg.
  2. It allows you to connect and communicate to many different types of servers with many different types of protocols.
  3. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols

Before using CURL, must check that it’s installed in server or your localhost. Here, I’ve given a simple example. This example uses the cURL functions to fetch the homepage into a file:

$ch = curl_init("");
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

  1. First initialize a cURL session using the curl_init()
  2. Set all your options for the transfer via the curl_setopt()
  3. Now you can execute the session with the curl_exec()
  4. Finally finish off your session using the curl_close().

For more information: please see PHP Manual.

Posted in PHP. Tags: , , , . 7 Comments »

7 Responses to “CURL – Client Url Library for PHP”

  1. gf4e Says:

    Well, CURL was very useful for me, because I had to organize my script’s work behind a proxy server, I did noit manage to find anything except CURL.

  2. junal Says:

    ohh what why you asked me ? he he …nice post. i see you are writing regularly. which is very good thing. Keep it up mahmud !

  3. mahmudahsan Says:

    Thanks junal vai, actually we should share something those are very essential for novice to intermediate php developer.

  4. rubel Says:

    Really Nice post…
    Could you please explain me… How can I save an image in my web server from other website?

    I really like your blog.
    Thank you.

  5. spyderwebtech Says:

    CURL is a very cool technology… I have used it to automate posts on Facebook, Myspace, and various other websites

    • vijay Says:

      Hi spyderwebtech,

      I have trouble to make automate posts on facebook, myspace and other websites.
      Please can you tell me about something about that?
      thanks in advance.

  6. Arsalan Says:

    How can i export Linkedin contacts using this ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: