somcaptcha

Gesponsorde koppelingen

PHP script bestanden

  1. somcaptcha

« Lees de omschrijving en reacties

*** afbeelding.php ***

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
<?php
session_start();
header("Content-type: image/gif");
header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: " . date("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");

//create image
$width = strlen($_SESSION['numberwork']) * 10;
$height = 18;
$image = imagecreate($width, $height);

//set white as transparant color
$backgroundcolor = imagecolorallocatealpha($image, 215, 215, 215, 127);
imagecolortransparent($image, $backgroundcolor);

//noise
for($i = 0; $i < 8; $i++) {
    $noiseColor = imagecolorallocate($image, rand(205, 255), rand(205, 255), rand(205, 255));
    $noiseX1 = rand(1, $width/2);
    $noiseY1 = rand(1, $height);
    $noiseX2 = rand($width/2, $width);
    $noiseY2 = rand(1, $height);
    imageline($image, $noiseX1, $noiseY1, $noiseX2, $noiseY2, $noiseColor);
    
    $text = rand(1,9);
    $fontsize = 12;
    $grey = rand(220, 255);
    $fontcolor = ImageColorAllocate($image, $grey, $grey, $grey);
    $font = 'fonts/GeosansLight.ttf';
    $angle = rand(-20,20);
    $x = rand(0, $width);
    $y = rand(0, $height);
    imagettftext($image, $fontsize, $angle, $x, $y, $fontcolor, $font, $text);
}


//add text
$text = $_SESSION['numberwork'];
for($i = 0; $i <= strlen($text); $i++) {
    $character = substr($text, $i, 1);
    $fontsize = rand(12,16);
    $fontcolor = ImageColorAllocate($image, rand(0,100), rand(0,100), rand(0,100));
    $font = 'fonts/GeosansLight.ttf';
    $angle = rand(-10,10);
    if ($character == 'i' || $character == 'l') {
        $x = $i * 10.5;
    }
else {
        $x = $i * 10;
    }

    $y = 14;
    imagettftext($image, $fontsize, $angle, $x, $y, $fontcolor, $font, $character);
}


//clean up
imagegif($image);
imagedestroy($image);
?>



*** voorbeeld.php ***
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
<?php
session_start();

if (isset($_POST['loginsum']) && $_POST['loginsum'] != "" && $_POST['loginsum'] == $_SESSION['loginsum']) {
    echo 'Correcte som';
}

if (isset($_POST['loginsum']) && $_POST['loginsum'] != "" && $_POST['loginsum'] != $_SESSION['loginsum']) {
    echo 'Foute som';
}


//numbers
$_NUMBERS = array();
$_NUMBERS[0] = "nul";
$_NUMBERS[1] = "een";
$_NUMBERS[2] = "twee";
$_NUMBERS[3] = "drie";
$_NUMBERS[4] = "vier";
$_NUMBERS[5] = "vijf";
$_NUMBERS[6] = "zes";
$_NUMBERS[7] = "zeven";
$_NUMBERS[8] = "acht";
$_NUMBERS[9] = "negen";
//calculations
$_CALCULATIONS = array();
$_CALCULATIONS[0] = "plus";
$_CALCULATIONS[1] = "min";

//generate random sum
$loginnumber1 = rand(0,9);
$loginnumber2 = rand(0,9);
$calculation = rand(0,1);
$_SESSION['numberwork'] = $_NUMBERS[$loginnumber1]." ".$_CALCULATIONS[$calculation]." ".$_NUMBERS[$loginnumber2];
if ($calculation == 0) {
    $sum = ($loginnumber1 + $loginnumber2);
}
else {
    $sum = ($loginnumber1 - $loginnumber2);
}

$_SESSION['loginsum'] = $sum;

?>

<form id="captcha_test" method="post" action="" onsubmit="">
<img src="afbeelding.php"> = <input name="loginsum" type="text" size="3" maxlength="3" /><br />
<input type="submit" value="test" />
</form>

 
 

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.