PHP Captcha Solver
Solve image captchas in PHP using cURL or Guzzle. FastCaptcha returns the solved text in 0.3β0.7 seconds β works with Laravel, Symfony, or plain PHP. No proprietary SDK needed.
PHP Captcha Solver β Code Examples
Plain PHP, Guzzle, and Laravel β all covered
Plain PHP (cURL)
<?php
function solveCaptcha(string $imagePath, string $apiKey): string {
$ch = curl_init('https://fastcaptcha.org/api/v1/ocr/');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["X-API-Key: {$apiKey}"],
CURLOPT_POSTFIELDS => [
'image' => new CURLFile($imagePath, 'image/png')
],
CURLOPT_TIMEOUT => 10,
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new RuntimeException("API error: HTTP {$httpCode}");
}
$data = json_decode($response, true);
return $data['text']; // "XK92B" in 0.3s
}
$result = solveCaptcha('captcha.png', 'YOUR_API_KEY');
echo $result; // "XK92B"
Guzzle HTTP Client
<?php
// composer require guzzlehttp/guzzle
require 'vendor/autoload.php';
use GuzzleHttp\Client;
function solveCaptcha(string $imagePath, string $apiKey): string {
$client = new Client([
'base_uri' => 'https://fastcaptcha.org',
'timeout' => 10.0,
]);
$response = $client->post('/api/v1/ocr/', [
'headers' => ['X-API-Key' => $apiKey],
'multipart' => [
[
'name' => 'image',
'contents' => fopen($imagePath, 'r'),
'filename' => 'captcha.png',
],
],
]);
$data = json_decode($response->getBody(), true);
return $data['text']; // "XK92B" in 0.3s
}
echo solveCaptcha('captcha.png', 'YOUR_API_KEY');
Laravel (Http Facade)
<?php
// In your Laravel controller or service
use Illuminate\Support\Facades\Http;
function solveCaptcha(string $imagePath): string {
$response = Http::withHeaders([
'X-API-Key' => config('services.fastcaptcha.key'),
])
->timeout(10)
->attach('image', file_get_contents($imagePath), 'captcha.png')
->post('https://fastcaptcha.org/api/v1/ocr/');
return $response->json('text'); // "XK92B" in 0.3s
}
// .env
// FASTCAPTCHA_KEY=your_api_key_here
// config/services.php
// 'fastcaptcha' => ['key' => env('FASTCAPTCHA_KEY')]
Solve from URL (PHP)
<?php
function solveCaptchaFromUrl(string $imgUrl, string $apiKey): string {
// Download image into memory
$imgData = file_get_contents($imgUrl);
$tmpFile = tempnam(sys_get_temp_dir(), 'captcha_') . '.png';
file_put_contents($tmpFile, $imgData);
$ch = curl_init('https://fastcaptcha.org/api/v1/ocr/');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["X-API-Key: {$apiKey}"],
CURLOPT_POSTFIELDS => [
'image' => new CURLFile($tmpFile, 'image/png')
],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
unlink($tmpFile);
return $result['text'];
}
$text = solveCaptchaFromUrl(
'https://example.com/captcha.png',
'YOUR_API_KEY'
);
echo $text; // "XK92B"
Start Solving Captchas in PHP Today
Free API key. 100 credits. No credit card. Works with any PHP framework.