PHP Class

Download RainCaptcha-1.1.0.php


To start using RainCaptcha, include the RainCaptcha-1.1.0.php file and create a new instance of the RainCaptcha class:

$rainCaptcha = new \RainCaptcha();

Getting the image

To get the URL of the CAPTCHA image, use the getImage() method of the RainCaptcha class:


Example: Displaying the image on a html page

If you want to display the CAPTHCA image on a web page, we recommend you to use an img tag:

	$rainCaptcha = new \RainCaptcha();
<img src="<?php echo $rainCaptcha->getImage(); ?>" />

Example: Editing the image on server side

You may want to edit the image on your server before returning it to the user. First, load image from RainCaptcha:

$rainCaptcha = new \RainCaptcha();
$captchaImageGd = imageCreateFromPNG($rainCaptcha->getImage());

Then, you can edit your image. For example, you can apply a colorize filter to it:

imageFilter($captchaImageGd, IMG_FILTER_COLORIZE, 240, 0, 0);

After you modified the image, you can return it to the user:

header('Content-type: image/png');

Checking the answer

To check whether the user's response is correct or not, use the checkAnswer($answer) method of the RainCaptcha class:


Where $captchaAnswer is a string with the submitted answer. If the submitted answer is correct, this method will return true, otherwise it will return false. Call this method only once; if you need to use the returned value more than once, save it in a variable.


if(!isset($_GET['captcha']) || empty($_GET['captcha']))
	echo 'You did not enter the CAPTCHA!';
else {
	$rainCaptcha = new \RainCaptcha();
 		echo 'You have passed the CAPTCHA test!';
		echo 'You have not passed the CAPTCHA test!';