Ich löse das mal aus der Schatzsuche heraus.
ClickableCaptcha.class.php
PHP
<?phpabstract class ClickableCaptcha { protected $width; protected $height; protected $left = 0, $top = 0; protected $size = 0; protected $im = null; protected $arcs, $lines, $fuzzBackGround = array(), $front; protected $colors = array(); public function __construct ($width = 300, $height = 120, $arcs = 15, $lines = 15, array $fuzzBackGround = array(false, 1,1, 1, 1), $foreGround = true) { $this->width = $width; $this->height = $height; $this->arcs = $arcs; $this->lines = $lines; $this->fuzzBackGround = $fuzzBackGround; $this->foreGround = $foreGround; } public function render() { $this->sendHeaders(); $this->im = imagecreate($this->width, $this->height); $this->setColors(); $this->getPositionOfSolver(); $this->fillBackGround(); if(!$this->foreGround) $this->renderSolver(); if($this->fuzzBackGround[0]) $this->fuzzBackGround(); for($i = 0; $i < $this->arcs; $i++) imagearc($this->im, rand(0,$this->width), rand(0, $this->height),rand(5,30),rand(5,30), 0, 360, ImageColorAllocate ($this->im, rand(00, 255), rand(0, 255), rand(0, 255))); for($i = 0; $i < $this->lines; $i++) imageline($this->im, rand(0,$this->width), rand(0, $this->height),rand(0,$this->width),rand(0, $this->height), ImageColorAllocate ($this->im, rand(0, 255), rand(0, 255), rand(0, 255))); if($this->foreGround) $this->renderSolver(); imagepng($this->im); } protected function sendHeaders() { header("Content-Type: image/png"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); } protected function setColors() { $this->colors['black'] = ImageColorAllocate ($this->im, 0, 0, 0); $this->colors['white'] = ImageColorAllocate ($this->im, 255, 255, 255); } protected function getPositionOfSolver($remove = false) { if(file_exists('pos')) { $pos = explode(' ', file_get_contents('pos')); $this->left = $pos[0]; $this->top = $pos[1]; $this->size = $pos[2]; } else { $this->size = rand(20,30); $this->left = rand((5 + $this->size/2), (($this->width - 5) - $this->size/2)); $this->top = rand((5 + $this->size/2), (($this->height - 5) - $this->size/2)); file_put_contents('pos', $this->left.' '.$this->top.' '.$this->size); } if($remove) unlink('pos'); } protected function fillBackGround() { imagefill($this->im, 0, 0, $this->colors['white']); } abstract protected function renderSolver(); protected function fuzzBackGround() { for($i = 0; $i < $this->width; $i = $i + rand($this->fuzzBackGround[1],$this->fuzzBackGround[2])) imageline($this->im, $i, 0, $i,$this->height, ImageColorAllocate ($this->im, rand(0, 255), rand(0, 255), rand(0, 255))); for($i = 0; $i < $this->height; $i = $i + rand($this->fuzzBackGround[1],$this->fuzzBackGround[2])) imageline($this->im, 0, $i, $this->width, $i, ImageColorAllocate ($this->im, rand(0, 255), rand(0, 255), rand(0, 255))); } public function check($x = null, $y = null) { $this->getPositionOfSolver(); if ($x === null || $y === null) return false; if ($x >= $this->left - $this->size/2 && $x <= ($this->left + $this->size/2) && $y >= $this->top - $this->size/2 && $y <= ($this->top + $this->size/2)) { $this->getPositionOfSolver(true); return true; } return false; }}?>
Die ClickableCaptcha bietet die grundlegenden Funktionen für das Clickbare Captcha, allerdings muss man die Klasse erweitern mit dem Aussehen des richtigen Bereiches:
OpenArcCaptcha.class.php
Die OpenArcCaptcha zeichnet einen offenen Kreis, der muss dann geklickt werden.
Und jetzt könnt ihr gerne eure Erweiterungen posten ;)
Aufruf:
PHP
<?php
define('WIDTH_OF_IMG', 300);
define('HEIGHT_OF_IMG', 300);
define('NUMBER_OF_RANDOM_ARCS', 15);
define('NUMBER_OF_RANDOM_LINES', 15);
define('RIGHT_RENDER_IN_FOREGROUND', true);
$fuzzyLinesInBackground = array(true,5,5,5,5); # array(ACTIVE, MIN_SPACE_BETWEEN_HORIZONTAL, MAX_SPACE_BETWEEN_HORIZONTAL,MIN_SPACE_BETWEEN_VERTICAL, MAX_SPACE_BETWEEN_VERTICAL);
require('OpenArcCaptcha.class.php');
$cap = new OpenArcCaptcha(WIDTH_OF_IMG,HEIGHT_OF_IMG,NUMBER_OF_RANDOM_ARCS,NUMBER_OF_RANDOM_LINES,$fuzzyLinesInBackground, RIGHT_RENDER_IN_FOREGROUND);
if($_GET['img']) {
$cap->render();
}
else {
var_dump($cap->check($_POST['pos_x'], $_POST['pos_y']));
?>
<form method="post" action="form.php">
<input type="image" name="pos" src="form.php?img=1" style="border: 1px solid black;" />
</form>
<?php } ?>
Alles anzeigen