Skip to content

Instantly share code, notes, and snippets.

@ndusan
Created June 21, 2012 21:50
Show Gist options
  • Save ndusan/2968766 to your computer and use it in GitHub Desktop.
Save ndusan/2968766 to your computer and use it in GitHub Desktop.
<?php
/**
* Anti-spam
*/
public function antiSpamAction()
{
$lenght=6;
$number = "";
for ($i = 1; $i <= $lenght; $i++)
{
$number .= rand(0,9)."";
}
$width = 11*$lenght;
$height = 30;
$img = ImageCreate($width, $height);
$background = imagecolorallocate($img,255,255,255);
$color_black = imagecolorallocate($img,0,0,0);
$color_grey = imagecolorallocate($img,169,169,169);
imagerectangle($img,0, 0,$width-1,$height-1,$color_grey);
imagestring($img, 5, $lenght, 7, $number, $color_black);
$_SESSION['anti-spam'] = $number;
//////// VERY IMPORTANT
header('Content-Type: image/png');
//////// VERY IMPORTANT
imagepng($img);
imagedestroy($img);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment