captchav2-spam-protection

Gesponsorde koppelingen

PHP script bestanden

  1. captchav2-spam-protection

« 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
70
71
72
73
74
75
76
77
78
79
80
81
<?php
#######################################
## © 2008 Wouter De Schuyter (Paradox)
## <[email protected]>
## http://paradox-productions.net/
## CAPTCHA V2.0 (SPAM PROTECTION)
#######################################


session_start(); // START SESSION

// FUNCTION TO SELECT A RANDOM CHARACTER OUT OF A STRING

function random_char($string) {
    $length = strlen($string);
    $position = mt_rand(0, $length - 1);
    return $string[$position];
}


$width = 50; // IMG WIDTH (PX)
$height = 20; // IMG HEIGHT (PX)
$characters = "0123456789"; // CHARACTERS FOR CAPTCHA STRING
$font = "fonts/font.ttf"; // FONT LOCATION
$fontS = 11; // FONT SIZE (PX)
$min = 25; // MIN NUMBER FOR THE RANDOM RGB TEXT COLOR
$max = 200; // MAX NUMBER FOR THE RANDOM RGB TEXT COLOR
$eBorder = true; // ENABLE BORDER, "true" TO ENABLE & "false" TO DISABLE
$eLines = true; // ENABLE LINES, "true" TO ENABLE & "false" TO DISABLE (RECOMMENDED TO ENABLE)
$MiLC = 200; // MIN LINE COLOR
$MaLC = 250; // MAX LINE COLOR
$maxLines = 10; // MAX LINES (RECOMMENDED BETWEEN 5 & 15)
// ADVANCED
////////////

$positionCharacterX = 3; // POSITION CHARACTER 1 ON THE X-AXIS (PX)
$characterSpace = 12; // SPACE FOR 1 CHARACTER (PX)
$positionCharactersY = 16; // SPACE ON THE Y-AXIS (PX)

// // // // // // // // // // // // //


$img = imagecreate($width, $height);
imagecolorallocate($img, 255, 255, 255); // BACKGROUND COLOR IN RGB

$randNr1 = rand($min, $max); // RANDOM NUMBER 1 BETWEEN $min & $max
$randNr2 = rand($min, $max); // RANDOM NUMBER 2 BETWEEN $min & $max
$randNr3 = rand($min, $max); // RANDOM NUMBER 3 BETWEEN $min & $max

$randomChar1 = random_char($characters); // RANDOM CHARACTER 1
$randomChar2 = random_char($characters); // RANDOM CHARACTER 2
$randomChar3 = random_char($characters); // RANDOM CHARACTER 3
$randomChar4 = random_char($characters); // RANDOM CHARACTER 4

$textcolor1 = imagecolorallocate($img, $randNr1, $randNr2, $randNr3); // TEXT COLOR 1
$textcolor2 = imagecolorallocate($img, $randNr2, $randNr3, $randNr1); // TEXT COLOR 2
$textcolor3 = imagecolorallocate($img, $randNr3, $randNr1, $randNr2); // TEXT COLOR 3
$textcolor4 = imagecolorallocate($img, $randNr3, $randNr2, $randNr1); // TEXT COLOR 4

if($eLines == true) {
    for($i=0; $i <= $maxLines; $i++) {
        $linesC = imagecolorallocate($img, rand($MiLC, $MaLC), rand($MiLC, $MaLC), rand($MiLC, $MaLC));
        imageline($img, rand(0, $width), rand(0, $height), rand(0, $width), rand(0, $height), $linesC);
    }
}


if($eBorder == true) {
    $bColor = imagecolorallocate($img, 175, 175, 175); // BORDER COLOR IN RGB
    imageline($img, 0, 0, $width, 0, $bColor);
    imageline($img, 0, $height, 0, 0, $bColor);
    imageline($img, $width-1, 0, $width-1, $height, $bColor);
    imageline($img, $width-1, $height-1, 0, $height-1, $bColor);
}


imagettftext($img, $fontS, 0, $positionCharacterX + 0 * $characterSpace, $positionCharactersY, $textcolor1, $font, $randomChar1); // CHARACTER 1
imagettftext($img, $fontS, 0, $positionCharacterX + 1 * $characterSpace, $positionCharactersY, $textcolor2, $font, $randomChar2); // CHARACTER 2
imagettftext($img, $fontS, 0, $positionCharacterX + 2 * $characterSpace, $positionCharactersY, $textcolor3, $font, $randomChar3); // CHARACTER 3
imagettftext($img, $fontS, 0, $positionCharacterX + 3 * $characterSpace, $positionCharactersY, $textcolor4, $font, $randomChar4); // CHARACTER 4

$_SESSION['captcha'] = $randomChar1 . $randomChar2 . $randomChar3 . $randomChar4; // CAPTCHA STRING FOR SESSION

header("content-type: image/png"); // CONTENT TYPE

imagepng($img); // CREATE IMAGE
imagedestroy($img); // DESTROY IMAGE
?>


font: http://projects.paradox-productions.net/CAPTCHA%5BV2%5D/fonts/font.ttf

 
 

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.