captcha-met-strepen

Gesponsorde koppelingen

PHP script bestanden

  1. captcha-met-strepen

« Lees de omschrijving en reacties

captcha.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
#####################################################
#####################################################
##                                                 ##
##       Captcha script by Laurens A. Laman.       ##
##      This script Makes a Code and put it in     ##
##      the variable $_SESSION['security_code']    ##
##    The User must type the code of the picture   ##
##       You can put it in a <img src=> tag        ##
##                                                 ##
##           Script tested on PHP 4.4.1            ##
##                                                 ##
#####################################################
#####################################################

##################################################
##################################################
##                                              ##
##                How to use it?                ##
##                                              ##
## This is very simple: just upload this script ##
##  Then access it like <img src="captcha.php"> ##
##                                              ##
##################################################
##################################################


###################################################
###################################################
##                                               ##
##                 Let's START:                  ##
##                                               ##
###################################################
###################################################


###################################################
###################################################
##                                               ##
##               Modify Variables:               ##
##                                               ##
###################################################
###################################################

$aant       = "5";//this varable can be 2-40
$height     = "30";
$SQUARE     = "1";//this varable can be 1 = ON, 0 = OFF
$possible   = 'BCDFGHJKLMNPQRSTUVWXY23456789';//Characters used in code
$Background = "Auto"; // this varible can be AUTO, WHITE, RED, GREEN, BLUE
$LINES      = "1";//Draw lines?  this varable can be 1 = ON, 0 = OFF
$LINES_OVER = "1";//Draw lines Over text? this varable can be 1 = ON, 0 = OFF
###########################################################
###########################################################
##                                                       ##
## DO NOT MODIFY BENEATH UNLESS YOU KNOW WHAT YOUR DOING ##
##                                                       ##
###########################################################
###########################################################
//Start de sessie

session_start();

  function
generateCode($characters,$possible) {
      
      $code = '';
      $i = 0;
      while ($i < $characters) {
         $code[] = substr($possible, mt_rand(0, strlen($possible)-1), 1);
         $codestr.=substr($possible, mt_rand(0, strlen($possible)-1), 1);
         $i++;
      }

      return $code;
   }


// Maak 't plaatje
$width= $aant * 25;
$im = imagecreate($width, $height);

//Achtergrond kleur
$Background = strtoupper ($Background);
if ($Background=="AUTO"){
$bg = imagecolorallocate($im, rand(190,255), rand(190,255), rand(190,255));
}
elseif($Background=="WHITE"){
$bg = imagecolorallocate($im, 255, 255, 255);
}
elseif($Background=="RED"){
$bg = imagecolorallocate($im, 255 , 0, 0);
}
elseif($Background=="GREEN"){
$bg = imagecolorallocate($im, 0, 255, 0);
}
elseif($Background=="BLUE"){
$bg = imagecolorallocate($im, 0, 0, 255);
}
else{
$bg = imagecolorallocate($im, 255, 255, 255);
}


// Genereer de code
$code= generateCode($aant,$possible);

if($LINES=="1" ){
// Teken variabele lijnen
$i=0;
while( $i<($width*$height)/150) {
    $noise_color = imagecolorallocate($im, rand(150,255), rand(150,255), rand(150,255));
    imageline($im, rand(0,$width), rand(0,$height), rand(0,$width), rand(0,$height), $noise_color);
          $i++;
}
}


if($SQUARE=="1" ){
// Teken een vierkand van 2 punten
$vierkand = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
imageline($im, 0, 0, $width, 0, $vierkand);
imageline($im, 0, 1, $width, 1, $vierkand);
imageline($im, $width-1, 0, $width-1, $height, $vierkand);
imageline($im, $width-2, 0, $width-2, $height, $vierkand);
imageline($im, $width-1, $height-1, 0, $height-1, $vierkand);
imageline($im, $width-1, $height-2, 0, $height-2, $vierkand);
imageline($im, 0, $height, 0, 0, $vierkand);
imageline($im, 1, $height, 1, 0, $vierkand);
}


$widthpercar= 25;
//zorg er voor dat de text niet over elkaar gaat staan
$i = 0;
      while ($i < $aant) {
          $min=($widthpercar*$i) - 1;
          $max=$widthpercar*$i;
          $textcolor = imagecolorallocate($im, rand(0,150), rand(0,150), rand(0,150));
if ($i == 0){
imagestring($im, 28, rand(0,$widthpercar), rand(0,$height-14), $code[$i], $textcolor);
}
elseif ($i==$aant){
imagestring($im, 28, rand($min+8,$max), rand(0,$height-14), $code[$i], $textcolor);
}
else{
imagestring($im, 28, rand($min+8,$max), rand(0,$height-14), $code[$i], $textcolor);
}

$codestr = $codestr . $code[$i];
$i++;
}



if($LINES_OVER=="1" ){
// teken voor de zekerheid nog ff 2 lijnen OVER de text
$i=0;
while( $i<2) {
     $noise_color = imagecolorallocate($im, rand(230,255), rand(230,255), rand(230,255));
         imageline($im, rand(0,$width), rand(0,$height), rand(0,$width), rand(0,$height), $noise_color);
          $i++;
}
}


$_SESSION['security_code']=$codestr;
// Print het plaatje
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);

?>

een voorbeeld form met imagereload functie (javascript)
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
<html>
<head>
  <title>Captcha Test Form</title>
</head>

<body>
<script>
function refreshimage(){

document.getElementById('vertimg').src = document.getElementById('vertimg').src + '#';
document.form1.security_code.value="";
   }
</script>
<?php
 session_start();
if (!empty($_POST)) {
   if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
      // Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
      $code = $_SESSION['security_code'];
      $mycode= $_POST['security_code'];
      echo"<font color=green>De code was corect <br>U vulde in: $mycode<br>gegenereerde code was: $code</font>";
      unset($_SESSION['security_code']);
   }
else {
       $code = $_SESSION['security_code'];
      $mycode= $_POST['security_code'];
      echo"<font color=red>De code was incorect <br>U vulde in: $mycode<br>gegenereerde code was: $code</font>";
      unset($_SESSION['security_code']);
   }
}

?>

<form name="form1" method="POST">
<img src="captcha.php" Name="vertimg" id="vertimg"><br />
<a href="#" onclick="refreshimage()">Can't read</A><BR>
<input type="text" name="security_code"  /><br />


<input type="submit" value="Submit Form" />
</form>

</body>
</html>

 
 

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.