PHP class for cURL

I discovered libcurl a long time ago, but never really worked with… until yesterday! It was during a Solaris course, my classmate showed me some stuff he did with libcurl, and I was amazed of the capabilities! On the evening I jumped onto my macbook and wrote a class to manage cURL requests.

My main utilization is to get quickly, and in an automatic manner, information on my accounts in some websites (such as social networks, affiliation programs or banks – yes, libcurl handle HTTPS!) and why not retrieving all of that in a widget.

Installation

Just download the class file, include it in your project and you’re good to go: cURL class

Usage example

$curl = new Curl(1);
 
// We pass variables in POST
$curl->addPostVar('login','cyril');
$curl->addPostVar('password','foobar');
 
// Connection to facebook, a cookie is created and stored in a file
$curl->exec('http://www.facebook.com/log.php');
 
// Now we can get a page as a logged user
$t = $curl->exec('http://www.facebook.com/profile.php');
 
// And do what we want with the result ...
// generally parsing it with regular expressions

That’s all folks!

Like it? Share it!

2 Responses to “PHP class for cURL”

  1. Alex
    Posted December 2, 2011 at 4:25 pm
    Permalink

    Change name of variable from “$r” to “$t” on line 104. It causes permanent looping.

  2. Posted December 2, 2011 at 4:29 pm
    Permalink

    Oh my god, bien vu Alex. Thanks.

Leave a Reply