Documentation

CaptchaGetCode

CMain::CaptchaGetCode(
) 

The method creates an CCaptchaclass object and returns the generated code. Non-static method.

Parameters

No parameters =

Examples of use

$code=$APPLICATION->CaptchaGetCode();

Then the code is passed in HTML format to create an image. The image is created via the script /bitrix/tools/captcha.php.

<input type="hidden" name="captcha_sid" value="<?=$code;?>" />
<img src="/bitrix/tools/captcha.php?captcha_sid=<?=$code;?>" alt="CAPTCHA" />

When executing the script, an image is generated, as well as a record is added to the data base. The CaptchaCheckCode method is called when processing the form:

if (!$APPLICATION->CaptchaCheckCode($_POST["captcha_word"], $_POST["captcha_sid"]))
{
   echo 'wrong captcha code';
}

To modify CAPTCHA for your site specifically, you can request theCCaptcha class directly when generating both the code and the image. It can be done as follows:

include_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/classes/general/captcha.php");
$cpt = new CCaptcha();
$cpt->SetCodeLength(6);  //set the length of code on the image 
$cpt->SetCode();
$code=$cpt->GetSID();

Modify the link in HTML:

<input type="hidden" name="captcha_sid" value="<?=$code;?>" />
<img src="[b]/bitrix/tools/captcha2.php[/b]?captcha_sid=<?=$code;?>" alt="CAPTCHA" />

Create the abovementioned captcha2.php and copy the contents of captcha.php into it.

Modify how the image is displayed:

$cpt = new CCaptcha();
$cpt->SetImageSize(90,30); //image size on output
//disabled background of circles and lines above the image
$cpt->SetEllipsesNumber(0); 
$cpt->SetLinesNumber(0);
//set the wave
$cpt->SetWaveTransformation(true);
//re-configured the text output 
// turning angles are kept by default, initial position, distances and font type are modified
$cpt->SetTextWriting($cpt->angleFrom, $cpt->angleTo, 5, 10, 16, 18);


© «Bitrix24», 2001-2024