getting vbulletin captcha image with curl
- by ermac2014
hi
I need to download Vbulletin captcha images on my HDD "from vbulletin register page" using curl and PHP. I really need to get samples of captcha images from several VBulletin boards. I'm collecting these samples for research purposes. anyway, here is what I done with curl till now.
1- download register.php page.
2- parse the downloaded page to get captcha image url.
3- download that image.
now I have done step 1 and 2 correctly. but in step 3 when I try to download the captcha image I don't get the captcha. I just get either a very tiny blank gif picture. or I get a png picture with vbulletin word on it. I really don't know what i'm doing wrong. I tried to output the html and push it to the browser the image shows correctly. but thats not what I want. I want to download the image and save it on my HDD.
here are some codes I've been working on:
//get contents with curl
function get_content($url)
{
$theString = parse_url($url);
$cookieName = $theString['host'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url."register.php");
curl_setopt($ch, CURLOPT_REFERER, $url."register.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)');
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies/cookie.txt"); //saved cookies
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies/cookie.txt"); //saved cookies
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$string = curl_exec ($ch);
//print_r(curl_getinfo($ch));
curl_close ($ch);
return $string;
}
//vbulletin main page
$url = 'http://blavbulletin.com/';
//get the page
$results = get_content($url);
if (preg_match_all('/<img[^>]*id\=\"imagereg\"[^>]*src\=\"([^\"]*)\"[^>]*>/s', $results , $captchaimages))
{
$captcha = $captchaimages[1][0];
echo "<img src='$url"."$captcha'>"; //when echoed the pic shows correctly
//now get the pic
$file = get_content("$url"."$captcha");
//save the pic on HDD
file_put_contents("captcha.jpg", $file);
}
any help would be appreciated..
regards,