Curl

Php and Curl

What is Curl:
Curl stands for ‘Client for urls’. Curl supports DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP. It also supports HTTPS certificates. The command is designed to work without user interaction or any kind of interactivity.

Php and Curl:
PHP supports libcurl, curl runs on PHP 4.0.2 or greater version. PHP requires that you use libcurl 7.0.2-beta or higher. To use cURL functions you need to install the http://curl.haxx.se/ libcurl package.
How to check curl :
If cURL support is enabled in PHP, the phpinfo() function will display it in its output as below. You are requested to check it before writing your first simple programme in PHP. Now check the tag ‘CURL support’ should be ‘enabled’.

How to get a web page through curl:
This is very easy to get a web page through cURL. The few line code need to complete this task.
<?php

$sUrl = ‘http://www.php.net&#8217;;//Put url whatever you want.

$ch = curl_init();//Initate curl

curl_setopt( $ch, CURLOPT_URL, $sUrl );//Set option

$result = curl_exec( $ch );//Execute curl command and returns a html page.

curl_close( $ch ); //Close curl and free resource

echo $result; //Print return web page.

?>

Idea behind the scene is
First of all we need to start cURL session with the help of curl_init() function. Then set cURL option what we desire after that we need to execute cURL command with the help of curl_exec( ) function. This function needs current cURL resource id which is $ch. The last step to close cURL resource and free memory to close cURL session use curl_close() function this function needs cURL resource id which is $ch.

Other article for cURL

Login in Joomla 1.5 site through curl

Resources:
http://curl.haxx.se
http://www.php.net/manual/en/intro.curl.php

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: