Friday, January 23, 2009

1) Getting the contents of files on remote servers with CURL : CURL is a powerful way to interact with remote servers with PHP. With CURL, it is possible to download files from remote servers
We’re coding a simple CURL function that can be used over and over. This function is simply for getting the contents of files on remote servers

2) File Handling With CURL : Using PHP's CURL module to fetch the example.com homepage and write the content in example_homepage.txt.

CURLOPT_FILE is an option for a CURL session identified by the ch parameter. $fp is a value set to the file that the transfer should be written to. The default is STDOUT (the browser window).
CURLOPT_HEADER is an option for a CURL session . It has Boolean value. Set TRUE to include the header in the output. Set False is not include the header in the output.

3) Submit A Form With CURL :
Here we’re going to learn how to submit a form using PHP and CURL.
So how do I use cURL to post data?
Begin by creating a new connection.
$curl_connection = curl_init('http://www.domainname.com/target_url.php');
A new connection is created using curl_init() function, which takes as parameter the target URL where we want to post our data. The target URL is the same as the “action” parameters of a normal form, which would look like this:

form start ("form action="http://www.domainname.com/target_url.php" method="post")
Now let’s set some options for our connection.
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

end of form

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home