Project

General

Profile

« Previous | Next » 

Revision 152

Added by ryan about 19 years ago

Updated Captcha code

View differences:

captcha.php
33 33
*/
34 34

  
35 35
$image = imagecreate(120, 30);
36

  
36 37
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
37 38
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
38 39
$darkgray = imagecolorallocate($image, 0x50, 0x50, 0x50);
40

  
39 41
srand((double)microtime()*1000000);
42

  
40 43
for ($i = 0; $i < 30; $i++) {
41 44
  $x1 = rand(0,120);
42 45
  $y1 = rand(0,30);
......
44 47
  $y2 = rand(0,30);
45 48
  imageline($image, $x1, $y1, $x2, $y2 , $gray);  
46 49
}
50

  
47 51
for ($i = 0; $i < 5; $i++) {
48 52
$cnum[$i] = rand(0,9);
49 53
}
54

  
50 55
for ($i = 0; $i < 5; $i++) {
51 56
 $fnt = rand(3,5);
52 57
 $x = $x + rand(12 , 20);
53 58
 $y = rand(7 , 12); 
54 59
 imagestring($image, $fnt, $x, $y, $cnum[$i] , $darkgray); 
55 60
}
61

  
56 62
$digit = "$cnum[0]$cnum[1]$cnum[2]$cnum[3]$cnum[4]";
63

  
64
session_start();
65
$_SESSION['captcha'] = $digit;
66

  
57 67
header('Content-type: image/png');
58 68
imagepng($image);
59 69
imagedestroy($image);

Also available in: Unified diff