gd-img-validatie-upate-1
Gesponsorde koppelingen
PHP script bestanden
======================
#--> de .htaccess (zet deze in dezelfde map als de image.png staat)
======================
<FilesMatch "\.(png)$" >
ForceType application/x-httpd-php
</FilesMatch>
======================
#--> index.php (just a test file :))
======================
Code (php)
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
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
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>GD Img Validatie Test</title>
<script type="text/javascript" language="javascript1.5">
<!--
function change_img()
{
num = Math.random()
num = num.toString();
num = num.substr(2, num.length);
document.getElementById('img').src = 'image.png?hash='+num;
return false;
}
//-->
</script>
<style type="text/css">
body, input {
font-family:tahoma;
font-size:12px;
}
form {
margin:20px;
padding:20px;
}
</style>
</head>
<body>
<?php
if(!isset($_POST['submit']))
{
?>
<form action="index.php" method="post">
Neem de text over om verder te gaan<br /><br />
<img id="img" style="border:1px solid #BEDFFB;" src="image.png" /> <a href="index.php" onclick="return change_img();">Change</a><br />
<input type="text" name="num" size="8" maxlength="5" onkeyup="this.value=this.value.toUpperCase();" style="margin-top:4px;" /><br /><br />
<input id="submit" type="submit" name="submit" value="Register" />
</form>
<?php
}
else
{
if(isset($_SESSION['num']) && strtoupper($_POST['num']) == $_SESSION['num'])
echo '<img src="goed.gif" alt="" /> Access Granted<br /><br />';
else
echo '<img src="fout.gif" alt="" /> Access Denied<br /><br />';
echo '<a href="index.php">back</a>';
}
?>
</body>
</html>
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>GD Img Validatie Test</title>
<script type="text/javascript" language="javascript1.5">
<!--
function change_img()
{
num = Math.random()
num = num.toString();
num = num.substr(2, num.length);
document.getElementById('img').src = 'image.png?hash='+num;
return false;
}
//-->
</script>
<style type="text/css">
body, input {
font-family:tahoma;
font-size:12px;
}
form {
margin:20px;
padding:20px;
}
</style>
</head>
<body>
<?php
if(!isset($_POST['submit']))
{
?>
<form action="index.php" method="post">
Neem de text over om verder te gaan<br /><br />
<img id="img" style="border:1px solid #BEDFFB;" src="image.png" /> <a href="index.php" onclick="return change_img();">Change</a><br />
<input type="text" name="num" size="8" maxlength="5" onkeyup="this.value=this.value.toUpperCase();" style="margin-top:4px;" /><br /><br />
<input id="submit" type="submit" name="submit" value="Register" />
</form>
<?php
}
else
{
if(isset($_SESSION['num']) && strtoupper($_POST['num']) == $_SESSION['num'])
echo '<img src="goed.gif" alt="" /> Access Granted<br /><br />';
else
echo '<img src="fout.gif" alt="" /> Access Denied<br /><br />';
echo '<a href="index.php">back</a>';
}
?>
</body>
</html>
======================
#--> image.png (een gewone php file ge-renamed naar .png)
======================
Code (php)
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
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
<?php
/********
* Starting Session
********/
session_start();
/********
* Function for creating random colors
********/
function random_color($im, $min, $max)
{
return imagecolorallocate($im, mt_rand($min, $max), mt_rand($min, $max), mt_rand($min, $max));
}
/********
* Some vars
********/
$im_width = 160;
$im_height = 40;
$font = 'font.ttf';
$font_size = 12;
/********
* Create img and draw background color
********/
$im = imagecreate($im_width, $im_height);
imagecolorallocate($im, 252, 252, 252);
/********
* Draw eclypses - (mischien nog effe kijken of ik ze variable kan maken, dat ze niet altijd op dezefde plaat komen)
********/
$color = random_color($im, 220, 250);
imageellipse($im, 10, 10, 110, 30, $color);
imageellipse($im, 11, 11, 111, 31, $color);
$color = random_color($im, 220, 250);
imageellipse($im, 110, 10, 110, 40, $color);
imageellipse($im, 111, 11, 111, 41, $color);
$color = random_color($im, 220, 250);
imageellipse($im, 90, 45, 140, 50, $color);
imageellipse($im, 90, 46, 141, 51, $color);
/********
* Make security code and draw to img (random colors per char)
********/
$chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
$max = strlen($chars) - 1;
$num = null;
for($i=0; $i<5; $i++)
{
$char = $chars{mt_rand(0, $max)};
$rotation = ($i % 2) ? -6 : 6;
imagettftext($im, $font_size, $rotation, $i * 26 + 20, 26, random_color($im, 50, 240), $font, $char);
$num .= $char;
}
/********
* Store Security code in Session
********/
$_SESSION['num'] = $num;
/********
* Output Image
********/
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
/********
* Starting Session
********/
session_start();
/********
* Function for creating random colors
********/
function random_color($im, $min, $max)
{
return imagecolorallocate($im, mt_rand($min, $max), mt_rand($min, $max), mt_rand($min, $max));
}
/********
* Some vars
********/
$im_width = 160;
$im_height = 40;
$font = 'font.ttf';
$font_size = 12;
/********
* Create img and draw background color
********/
$im = imagecreate($im_width, $im_height);
imagecolorallocate($im, 252, 252, 252);
/********
* Draw eclypses - (mischien nog effe kijken of ik ze variable kan maken, dat ze niet altijd op dezefde plaat komen)
********/
$color = random_color($im, 220, 250);
imageellipse($im, 10, 10, 110, 30, $color);
imageellipse($im, 11, 11, 111, 31, $color);
$color = random_color($im, 220, 250);
imageellipse($im, 110, 10, 110, 40, $color);
imageellipse($im, 111, 11, 111, 41, $color);
$color = random_color($im, 220, 250);
imageellipse($im, 90, 45, 140, 50, $color);
imageellipse($im, 90, 46, 141, 51, $color);
/********
* Make security code and draw to img (random colors per char)
********/
$chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
$max = strlen($chars) - 1;
$num = null;
for($i=0; $i<5; $i++)
{
$char = $chars{mt_rand(0, $max)};
$rotation = ($i % 2) ? -6 : 6;
imagettftext($im, $font_size, $rotation, $i * 26 + 20, 26, random_color($im, 50, 240), $font, $char);
$num .= $char;
}
/********
* Store Security code in Session
********/
$_SESSION['num'] = $num;
/********
* Output Image
********/
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>