captcha.php

Gesponsorde koppelingen

PHP script bestanden

  1. index.html
  2. captcha.php
  3. controleren.php

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
function captcha($string){
    header("content-type: image/png");
    $height = 100;
    $ringen = 10;
    $fonts = glob("fonts/*.ttf");
    //print_r($fonts);
    $width = (strlen($string)+2)*50;
    $image = imagecreate($width, $height);
    $black = imagecolorallocate($image, 0, 0, 0);
    $white = imagecolorallocate($image, 255, 255, 255);
    imagefilledrectangle($image, 0, 0, $width, $height, $white);
    foreach(str_split($string) as $key => $value){
        $angle = mt_rand(-45, 45);
        if($angle < 0){
            $corner1 = 5;
            $corner2 = 1;
        }
else{
            $corner1 = 7;
            $corner2 = 3;
        }

        for(;;){
            $r = mt_rand(0, 255);
            $g = mt_rand(0, 255);
            $b = mt_rand(0, 255);
            if($r+$g+$b<230 || $r+$g+$b == 0){
                break;
            }
        }

        imagefttext($image, mt_rand(30, 50), $angle, ($key+1) * 50 + mt_rand(-10, 10), ($height/2)+15 + mt_rand(-10, 10), imagecolorallocate($image, $r, $g, $b), $fonts[mt_rand(0, count($fonts)-1)], $value);
        $r = 0;
        $g = 0;
        $b = 0;
    }

    for($i=0;$i<$ringen;$i++){
        for(;;){
            $r = mt_rand(0, 255);
            $g = mt_rand(0, 255);
            $b = mt_rand(0, 255);
            if($r+$g+$b<230 || $r+$g+$b == 0){
                break;
            }
        }

        imageellipse($image, mt_rand(-10, $width-10), mt_rand(-10, $height-10), mt_rand(20, $width+20), mt_rand(20, $height+20), imagecolorallocate($image, $r, $g, $b));
        $r = 0;
        $g = 0;
        $b = 0;
    }

    imagepng($image);
    imagedestroy($image);
}

function
random($size){
        $chars = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"
,"0","1","2","3","4","5","6","7","8","9");
    for($i=1;$i<=$size;$i++){
        $string .= $chars[mt_rand(0, count($chars)-1)];
    }

    return $string;
}


session_start();
$string = random(6);
if(isset($_SESSION["captcha"])){
    unset($_SESSION['captcha']);
}

$_SESSION["captcha"] = md5($string);
captcha($string);
?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.