Remotely login script throw curl in php
Posted on 21. Apr, 2009 by admin in php
As we know php doesnt cum up with curl support by default for this u have to download a separte module libcurl which is basically for php. Using curl you can login to another site , grab the data and then log it off , just like a simple user do , you can use the below script for login to another site using curl
<?php
// INIT CURL
$ch = curl_init();
// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, ‘http://www.external-site.com/Members/Login.php’);
// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);
// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, ‘fieldname1=fieldvalue1&fieldname2=fieldvalue2′);
// IMITATE CLASSIC BROWSER’S BEHAVIOUR : HANDLE COOKIES
curl_setopt ($ch, CURLOPT_COOKIEJAR, ‘cookie.txt’);
# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);
// SET FILE TO DOWNLOAD
curl_setopt($ch, CURLOPT_URL, ‘http://www.external-site.com/Members/Downloads/AnnualReport.pdf’);
// EXECUTE 2nd REQUEST (FILE DOWNLOAD)
$content = curl_exec ($ch);
// CLOSE CURL
curl_close ($ch);
?>

3 Comments
Remotely login script throw curl in php | Webmaster Tools
21. Apr, 2009
[...] See the rest here: Remotely login script throw curl in php [...]
How I Lost Thirty Pounds in Thirty Days
03. May, 2009
Hi, interesting post. I have been wondering about this issue,so thanks for writing. I’ll definitely be subscribing to your blog.
Health Tips
06. May, 2009
Hi, cool post. I have been pondering this topic,so thanks for writing. I will likely be subscribing to your posts. Keep up the good posts
Leave a reply