bruce6667
Junior Member
- Apr 6, 2008
- 136
- 106
What's cUrl?
cUrl is a set of functions for php that emulate a browser. You can use it to do things like scraping and spamming. Basically, cUrl lets you automate and repeat any web action.
Basic example of screen scraping
So there are four stages:
// 1. start it up
$ch = curl_init();
// 2. set some options
curl_setopt($ch, CURLOPT_URL, 'http://www.google.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 3. execute it... you don't have to echo
echo curl_exec($ch);
// 4. close it
curl_close($ch);
Most Common Options
CURLOPT_URL -> the url you want to GET/POST to
CURLOPT_RETURNTRANSFER -> return it instead of printing it
CURLOPT_REFERER -> you can fake the referer if you want
CURLOPT_USERAGENT -> you can fake this as well
CURLOPT_FOLLOWLOCATION -> follow any redirects
CURLOPT_POST -> you can do POSTs with cUrl, example: submitting a form
CURLOPT_POSTFIELDS -> you have to tell it what to post
Examples of Most Common Options
Sometimes its easier to set POSTFIELDS in an array.
Limitations... cUrl doesn't do javascript or flash. That's about it.
cUrl is a set of functions for php that emulate a browser. You can use it to do things like scraping and spamming. Basically, cUrl lets you automate and repeat any web action.
Basic example of screen scraping
Code:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.google.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
curl_close($ch);
?>
So there are four stages:
// 1. start it up
$ch = curl_init();
// 2. set some options
curl_setopt($ch, CURLOPT_URL, 'http://www.google.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 3. execute it... you don't have to echo
echo curl_exec($ch);
// 4. close it
curl_close($ch);
Most Common Options
CURLOPT_URL -> the url you want to GET/POST to
CURLOPT_RETURNTRANSFER -> return it instead of printing it
CURLOPT_REFERER -> you can fake the referer if you want
CURLOPT_USERAGENT -> you can fake this as well
CURLOPT_FOLLOWLOCATION -> follow any redirects
CURLOPT_POST -> you can do POSTs with cUrl, example: submitting a form
CURLOPT_POSTFIELDS -> you have to tell it what to post
Examples of Most Common Options
Code:
curl_setopt($ch, CURLOPT_URL, 'http://blackhatworld.com')
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true)
curl_setopt($ch, CURLOPT_REFERER, 'http://gmail.com')
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla')
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true)
curl_setopt($ch, CURLOPT_POST, true)
curl_setopt($ch, CURLOPT_POSTFIELDS, 'boo=radley&atticus=finch')
Sometimes its easier to set POSTFIELDS in an array.
Code:
$postfields = array(
'boo' => 'radley',
'do' => 'why not',
'name' => 'bruce6667',
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $posfields)
Limitations... cUrl doesn't do javascript or flash. That's about it.