PHP class for cURL

Posted on November 6, 2008
by

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!

About the author

Cyril Mazur is a serial web entrepreneur with experience in various fields: online dating, forex & finance, blogging, online advertising... who enjoys building things that people like to use.

5 comments