CURL and PHP
CURL :
The name is a play on ‘Client for URLs’. ITs a project
which allows you to connect and communicate to many different types of servers with many different types of protocols.
CURL and PHP:
CURL is one of the extensions to PHP .Using CURL our PHP script
can open a file which are not is the same server. We can also POST
variable to the script in other Server using CURL.
To use CURL libcurl package should be installed and curl extension should be enabled in php.ini.
CURL supports HTTP,HTTP POST,HTTP PUT,FTP uploading, HTTPS certificates
Simple CURL REQUEST:
<?php
$ch = curl_init(); ///// initializing curl session
curl_setopt ($ch, CURLOPT_URL, “http://www.google.com/”);
/*
This is the URL that you want PHP to fetch. You can also set this option when initializing a session with the curl_init() function
*/
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close ($ch);
?>
The above script will output the google page
If you don’t want to output the page and you want to play
with the source the you can get the source in a string and use it
by setting
CURLOPT_RETURNTRANSFER to non zero
like
curl_setopt ($ch, CURLOPT_RETURNTRANSFE,1 );
and make execute as
$str = curl_exec ($ch);
