Posted by Liger on Sat 18 Oct 07:12
report abuse | View followups from anthony, gogo and Anonymous | download | new post
- <?php
- //
- // Configuration
- //
- //Your API key
- $api_key = '123-123-123-123-123';
- //Path to captcha image
- //Url to CaptchaKiller API
- $url = 'http://www.captchakiller.com/api.php';
- //
- // Functions
- //
- function upload_captcha($api_key, $file)
- {
- global $crl;
- 'method' => 'upload_captcha',
- 'api_key' => $api_key,
- 'file' => "@$file",
- 'expire' => '300',
- 'rights' => 'false'
- );
- curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata);
- $result = curl_exec($crl);
- $headers = curl_getinfo($crl);
- if ($headers['header_size'] == 0)
- {
- curl_close($crl);
- }
- else
- {
- echo 'Successfully uploaded captcha<br />';
- }
- //Parse captcha ID
- $captcha_id = 0;
- if($pos !== false)
- {
- $pattern = '([\w\-]+)';
- {
- $captcha_id = $matches[0];
- }
- else
- {
- }
- }
- else
- {
- echo $result;
- }
- return $captcha_id;
- }
- function get_result($api_key, $captcha_id)
- {
- global $crl;
- //Send request for captcha result
- 'method' => 'get_result',
- 'api_key' => $api_key,
- 'captcha_id' => $captcha_id
- );
- curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata);
- $result = curl_exec($crl);
- $headers = curl_getinfo($crl);
- if ($headers['header_size'] == 0)
- {
- curl_close($crl);
- }
- return $result;
- }
- function process_captcha($api_key, $file, $url)
- {
- $captcha_id = upload_captcha($api_key, $file, $url);
- $captcha_result = '';
- if($captcha_id != 0)
- {
- echo 'Getting result';
- for($i = 0; $i < 20; $i++)
- {
- //Wait a few seconds before sending the next request
- //Get the result
- $result = get_result($api_key, $captcha_id);
- //Parse the result
- if($pos_success !== false)
- {
- $pattern = '(.*)';
- {
- }
- else
- {
- }
- break;
- }
- else if($pos_wait !== false)
- {
- //WAIT found, try again
- echo '.';
- continue;
- }
- else
- {
- //FAILURE found
- break;
- }
- if($i == 19)
- {
- echo '<br />20 attempts have passed and still received WAIT<br />';
- }
- }
- }
- return $captcha_result;
- }
- //
- // Main program
- //
- // Start the cURL session
- $crl = curl_init();
- curl_setopt($crl, CURLOPT_URL, $url);
- curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
- $captcha = process_captcha($api_key, $file, $url);
- //Close the cURL session
- curl_close($crl);
- ?>
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.