Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- session_start();
- class captcha
- {
- public $CAPTCHA_TYPE_CALC = 1;
- public $CAPTCHA_TYPE_CHARS = 2;
- //Einstellungen
- private $stringLength = 6;
- private $calcMaxValue = 10;
- private $characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- //Einstellungen
- public function create($type){
- header("Content-Type: image/png");
- if($type == $this->CAPTCHA_TYPE_CALC){
- $img = ImageCreate(300, 100);
- $black = ImageColorAllocate($img, 0 , 0, 0);
- $positionX = 70;
- $digit = Array(rand(0, $this->calcMaxValue), rand(0, $this->calcMaxValue));
- for($i = 0; $i < count($digit); $i++){
- $rotation = rand(0, 30);
- $r = rand(0,255);
- $g = rand(0,255);
- $b = rand(0,255);
- $white = ImageColorAllocate($img, $r, $b, $g);
- imagettftext($img, 30.5, $rotation, $positionX, 60, $white, "./fonts/TAHOMA.TTF", $digit[$i]);
- if($i == 0){
- $positionX += 90;
- imagettftext($img, 30.5, $rotation, $positionX, 60, $white, "./fonts/TAHOMA.TTF", "+");
- }
- $positionX += 90;
- }
- $_SESSION["calcResult"] = $digit[0] + $digit[1];
- }else if($type == $this->CAPTCHA_TYPE_CHARS){
- $img = ImageCreate($this->stringLength * 50, 100);
- $black = ImageColorAllocate($img, 0 , 0, 0);
- $positionX = 70;
- for($i = 0; $i < $this->stringLength; $i++) {
- $rotation = rand(0, 45);
- $r = rand(0,255);
- $g = rand(0,255);
- $b = rand(0,255);
- $white = ImageColorAllocate($img, $r, $b, $g);
- $char = $this->characters[rand(0, strlen($this->characters))];
- $size = rand(30, 50);
- imagettftext($img, $size, $rotation, $positionX, 60, $white, "./fonts/ARIAL.TTF", $char);
- $positionX += ($size - 10);
- $string .= $char;
- }
- $_SESSION["charsResult"] = $string;
- }
- ImagePNG($img);
- ImageDestroy($img);
- }
- public function checkCaptcha($type, $result){
- if($type == $this->CAPTCHA_TYPE_CALC){
- if($result == $_SESSION["calcResult"]){
- return true;
- }else{
- return false;
- }
- }else if($type == $this->CAPTCHA_TYPE_CHARS){
- if($result == $_SESSION["charsResult"]){
- return true;
- }else{
- return false;
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement