Skip to content

Instantly share code, notes, and snippets.

@GiovanniK
Created February 27, 2014 13:59
Show Gist options
  • Save GiovanniK/9250569 to your computer and use it in GitHub Desktop.
Save GiovanniK/9250569 to your computer and use it in GitHub Desktop.
Simple captcha
<?php
session_start();
if (empty($_SESSION['captcha']))
{
$captcha = mt_rand(10000, 99999);
$_SESSION['captcha'] = $captcha;
}
else
{
$captcha = $_SESSION['captcha'];
}
unset ($_SESSION['captcha']);
header ('Content-Type: image/png');
$im = @imagecreatetruecolor(100, 40) or die('GD library not found :(');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 10, 27, 10, $captcha, $text_color);
imagepng($im);
imagedestroy($im);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment