Captcha bypass tutorials

Was this helpful?

How to Use `strtoupper` with 2captcha to Handle Text Captchas

Matthew Modi

Technical engineer

Introduction

When working with 2captcha to solve simple captchas (normal or textcaptcha), you'll often encounter a situation where the solver returns an answer that doesn't match the expected letter case, while the target website requires a strict format. The strtoupper() function (or mb_strtoupper() for UTF-8) allows you to normalize the response before submitting it to the form. Below is a step-by-step integration guide.

Step 1. Configure the regsense Parameter in Your 2captcha Request

By default, 2captcha uses case-sensitive recognition (regsense=1). If your target website does not require exact case matching, send the request with regsense=0. This provides the following advantages:

  • Speeds up task processing by solvers.
  • Reduces the rate of tasks sent back for revision.
  • Lets you format the output to your exact needs on the receiving end.

Example task submission (PHP cURL):

php Copy
$params = [
    'key'           => 'YOUR_2CAPTCHA_KEY',
    'method'        => 'normal',
    'body'          => base64_encode($captchaImage),
    'regsense'      => 0,
    'languagepool'  => 'ru', // Routes the task to solvers familiar with the required alphabet
    'json'          => 1
];

$ch = curl_init('https://2captcha.com/in.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = json_decode(curl_exec($ch), true);
$taskId = $response['request'] ?? null;
curl_close($ch);

Step 2. Retrieve the Response and Apply Normalization

After receiving the OK status from res.php, you'll get a text response. Important: if you used json=1 in in.php, you must also pass this parameter explicitly to res.php; otherwise, the service will return the plain OK|answer format. Polling for the result is best done at 5–10 second intervals until the answer is ready.

Example response processing:

php Copy
$answer = trim($captchaResultFrom2captcha);
// strtoupper() is sufficient for Latin; mb_strtoupper() is required for Cyrillic/UTF-8
$normalized = mb_strtoupper($answer, 'UTF-8');

Step 3. Integrate Normalization into Form Submission

Use $normalized as the captcha field value in your POST/GET request to the target website.

Example integration into form submission:

php Copy
$formData = [
    'username' => 'test_user',
    'password' => 'secret123',
    'captcha'  => $normalized
];

$ch = curl_init('https://target-site.com/login.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($formData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

Step 4. Account for Language-Specific Case Conversion Features

The standard strtoupper() function in PHP only processes ASCII characters. When working with multilingual captchas, it's crucial to choose the right case-conversion method based on your programming language and character encoding.

Case Conversion Comparison by Language

Language Function/Method Key Characteristics
PHP strtoupper($text) ASCII/Latin only
PHP mb_strtoupper($text, 'UTF-8') Supports Cyrillic & Unicode; requires mbstring
Python text.upper() Native Unicode support
C# text.ToUpper() Default conversion
C# text.ToUpper(CultureInfo) Locale-aware conversion
Ruby text.upcase Default conversion
Ruby text.upcase(:unicode) Unicode-aware
JavaScript text.toUpperCase() Broad Unicode support
Java text.toUpperCase() Default conversion
Java text.toUpperCase(Locale) Locale-aware conversion

Key Recommendations:

  • PHP: Always use mb_strtoupper($text, 'UTF-8') for captchas containing Cyrillic or mixed alphabets. Ensure the mbstring extension is enabled in your php.ini.
  • Python/JavaScript: .upper() and .toUpperCase() handle Unicode natively, but watch for edge cases with special characters (e.g., German ß becomes SS in Python).
  • C#/Java: When processing international captchas, explicitly specify the locale (CultureInfo.InvariantCulture or Locale.ENGLISH) to prevent unexpected transformations.
  • Ruby: For full Unicode compliance, use upcase(:unicode).

Step 5. Testing and Logging

Add a simple verification step: compare $answer and $normalized. If they differ, log the discrepancy. This helps you quickly identify websites that are actually case-sensitive despite your initial assumptions.

Final Pre-Launch Checklist

  • Case-insensitivity has been verified on the target website.
  • regsense=0 is set in the 2captcha request.
  • languagepool is added for multilingual captchas.
  • The code uses mb_strtoupper($text, 'UTF-8') (or language equivalent).
  • The response is trimmed before applying case conversion.
  • Logging for case mismatches is configured.
  • Testing has been performed on 30–50 real captchas.