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);
- Kiran's blog
- 470 reads













Post new comment