The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 23, 2019, 10:23:18 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: 1 captcha wrecking my buzz  (Read 1830 times)
krustee
Rookie
**
Offline Offline

Posts: 33


View Profile
« on: November 02, 2009, 04:30:27 PM »

Howdy folks, here I am with yet another n00b question that is really busting my balls.

A quick overview of the situation. I am using php/curl to try automate a webform.
The captcha url is always static ie. http://site.com/act/captcha.jpg
There is a token on the register page that also needs to be scraped.

However my problem lies herein. I scrape the register page and parse the token number. I then scrape the captcha url alas all my efforts are for naught as this image is not the same as the one originally displayed on the register page. I think I verified this as when I right click and view image on the original captcha it also changes the image when displayed.

What I think is happening is that when I request the captcha after already scraping the register page it is altering the cookie and giving me a new image. here is a quick sampling of the function I am using, the scrape_page function is shown below:

Code:
function get_token($site)
{
// delete any remaining cookies
if(file_exists("cookies/cookies.tmp"))
unlink("cookies/cookies.tmp");
       
$register_page = scrape_page($site, "https://site.com/act/register");
preg_match("/name=\"token\" value=\"(.*?)\" \/>/", $register_page, $matches);
preg_replace("/name=\"token\" value=\"/", "", $matches[0]);
$token = $matches[1];

$captcha_url = "https://site.com/act/Captcha.jpg";
$fp = fopen("captcha/captcha.jpg", "w");
fwrite($fp, scrape_page($captcha_url, "https://site.com/act/register"));
fclose($fp);

return $token;
}

Code:
function scrape_page($page, $reffer)
{
// cookie path
$file_cookie = "cookies/cookies.tmp";
$ch = curl_init($page);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $file_cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $file_cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");


$response = curl_exec($ch);
curl_close($ch);

//echo curl_error($ch);
return $response;
}

Major kudos to anyone who can help me solve this.

ps. wasn't sure to post this in the php section or here so to the powers that be you may move it if you deem necessary.
Logged
Bompa
Administrator
Lifer
*****
Offline Offline

Posts: 564


Where does this show?


View Profile
« Reply #1 on: November 02, 2009, 06:21:07 PM »

If the token is not changing with the image, then it's a matter of image and cookies, right?

Bompa
Logged

"The most beautiful and profound emotion we can experience is the sensation of the mystical..." - Albert Einstein
krustee
Rookie
**
Offline Offline

Posts: 33


View Profile
« Reply #2 on: November 02, 2009, 06:26:35 PM »

hey bomps thanks for the input, but I got this solved. Had the directory where the captcha image is saved open while I ran the script and noticed something strange, the captcha image was been downloaded twice. Went back and checked my code and yes I don't need to explain I'm an idiot.
Logged
Bompa
Administrator
Lifer
*****
Offline Offline

Posts: 564


Where does this show?


View Profile
« Reply #3 on: November 02, 2009, 11:33:05 PM »

hey bomps thanks for the input, but I got this solved. Had the directory where the captcha image is saved open while I ran the script and noticed something strange, the captcha image was been downloaded twice. Went back and checked my code and yes I don't need to explain I'm an idiot.

LOL I do shit like that all the time. It's amazing I get anything done.

Logged

"The most beautiful and profound emotion we can experience is the sensation of the mystical..." - Albert Einstein
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!