An introduction to using Curl

0
Your rating: None

This utility, which stands for client URLs (and is also written as just curl or
Curl), is a command-line tool for working with URLs. With cURL you can access Websites, FTP files, and do much, much more.PHP can use cURL via the shell_exec() and other system functions. But PHP also supports libcurl, a cURL library.

The process starts by using curl_init(), providing this function the name of the URL being accessed:

$curl = curl_init(‘www.example.com’);

The value returned by the function should be assigned to a variable, which will act as a pointer or a handle to the transaction. Next, the curl_setopt() function is used (a lot) to set any options. The syntax is:

curl_setopt($curl, CONSTANT, value);

Unfortunately, there are way too many options to even provide a subset here. In
the following example I’ll highlight a handful of them. If you take to cURL, check out the PHP manual for the full list of settings.

After setting all the options (and note that you can set them in any order), use
curl_exec() to execute the transaction:

$result = curl_exec($curl);

You should assign the result of the curl_exec() command to a variable, in case
you need to print the result.

Finally, close the connection:

curl_close($curl);

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.

Jobs in India