random-image-verificatie-captcha

Gesponsorde koppelingen

PHP script bestanden

  1. random-image-verificatie-captcha

« 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
session_start ( );
srand ( microtime ( ) * 100000000 );
function
gen_string ( $num_chars = 6 )
{

    $chars = '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 1 2 3 4 5 6 7 8 9 0';
    $chars = explode ( ' ', $chars );
    for ( $i = 0; $i < $num_chars; $i++ )
    {

        if ( strlen ( $return ) < $num_chars )
        {

            $return .= $chars[rand ( 0, ( count ( $chars ) - 1 ) )];
        }
    }

    return $return;
}

if ( $_POST )
{

    if ( md5 ( base64_encode ( $_POST['code'] ) ) == $_POST['the_code'] )
    {

        die ( '<font color="#008000">Correcte Code!</font>' );
    }

    else
    {
        die ( '<font color="#800000">Foute Code!</font>' );
    }
}

if ( isset ( $_GET['image'] ) )
{

    // Alle instellingen:D
    session_start ( );
    $code = ( $_SESSION['string'] ) ? base64_decode ( $_SESSION['string'] ) : 'ReLoAd';
    $lines = 25;
    $dots = 100;
    $width = strlen ( $code ) * 20;
    $height = 30;
    $im = imagecreate ( $width, $height );
    // kleuren
    $bg = imagecolorallocate ( $im, 0xff, 0xff, 0xff );
    $text_color = imagecolorallocate ( $im, 0x00, 0x00, 0x00 );
    $line_color = imagecolorallocate ( $im, 0x00, 0x80, 0x00 );
    $dot_color = imagecolorallocate ( $im, 0x80, 0x00, 0x00 );
    imagecolortransparent ( $im );
    // lijnen
    for ( $line = 0; $line < $lines; $line++ )
    {

        imageline ( $im, rand ( 0, $width ), rand ( 0, $height ), rand ( 0, $width ), rand ( 0, $height ), $line_color );
    }


    // stippen
    for ( $dot = 0; $dot < $dots; $dot++ )
    {

        imagesetpixel ( $im, rand ( 0, $width ), rand ( 0, $height ), $dot_color );
    }


    // en nu het ECHTE werk:D
    // de tekst

    $chars = preg_split ( '//', $code );
    $x = -12;

    for ( $i = 0; $i < count ( $chars ); $i++ )
    {

        imagechar ( $im, rand ( 5, 5 ), $x, rand ( 0, $height - 15 ), $chars[$i], $text_color);
        $x = $x + 20;
    }


    if ( function_exists ( 'imagegif' ) )
    {

        header ( 'Content-Type: image/gif' );
        imagegif ( $im );
    }

    elseif ( function_exists ( 'imagejpeg' ) )
    {

        header ( 'Content-Type: image/jpeg' );
        imagejpeg ( $im );
    }

    imagedestroy ( $im );
}

else
{
    $characters = ( $_GET['chars'] ) ? $_GET['chars'] : 6;
    $_SESSION['string'] = base64_encode ( gen_string ( $characters ) );
?>

<html dir="ltr">
<head>
<title>Verificatie Test</title>
</head>
<body bgcolor="grey">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="code" maxlength="6" size="6">&nbsp;&nbsp;&nbsp;<img src="<?php echo $_SERVER['PHP_SELF']; ?>?image" height="30px" width="<?php echo ( 20 * $characters ); ?>px" alt="Code">
<br /><input type="hidden" name="the_code" value="<?php echo md5 ( $_SESSION['string'] ); ?>"><input type="submit">
</form>
</body>
</html>
<?php
}
?>

 
 

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.