| 1 | 145 | ryan | <?php
 | 
      
        | 2 |  |  | 
 | 
      
        | 3 |  |  | // $Id$
 | 
      
        | 4 |  |  | 
 | 
      
        | 5 |  |  | /*
 | 
      
        | 6 |  |  | 
 | 
      
        | 7 |  |  |  Website Baker Project <http://www.websitebaker.org/>
 | 
      
        | 8 |  |  |  Copyright (C) 2004-2005, Ryan Djurovich
 | 
      
        | 9 |  |  | 
 | 
      
        | 10 |  |  |  Website Baker is free software; you can redistribute it and/or modify
 | 
      
        | 11 |  |  |  it under the terms of the GNU General Public License as published by
 | 
      
        | 12 |  |  |  the Free Software Foundation; either version 2 of the License, or
 | 
      
        | 13 |  |  |  (at your option) any later version.
 | 
      
        | 14 |  |  | 
 | 
      
        | 15 |  |  |  Website Baker is distributed in the hope that it will be useful,
 | 
      
        | 16 |  |  |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
      
        | 17 |  |  |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
      
        | 18 |  |  |  GNU General Public License for more details.
 | 
      
        | 19 |  |  | 
 | 
      
        | 20 |  |  |  You should have received a copy of the GNU General Public License
 | 
      
        | 21 |  |  |  along with Website Baker; if not, write to the Free Software
 | 
      
        | 22 |  |  |  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
      
        | 23 |  |  | 
 | 
      
        | 24 |  |  | */
 | 
      
        | 25 |  |  | 
 | 
      
        | 26 |  |  | /*
 | 
      
        | 27 |  |  | 
 | 
      
        | 28 |  |  | Captcha generator
 | 
      
        | 29 |  |  | 
 | 
      
        | 30 |  |  | This file generates a captcha image.
 | 
      
        | 31 |  |  | Credits to http://php.webmaster-kit.com/ for the original code.
 | 
      
        | 32 |  |  | 
 | 
      
        | 33 |  |  | */
 | 
      
        | 34 |  |  | 
 | 
      
        | 35 |  |  | $image = imagecreate(120, 30);
 | 
      
        | 36 | 152 | ryan | 
 | 
      
        | 37 | 145 | ryan | $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
 | 
      
        | 38 |  |  | $gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
 | 
      
        | 39 |  |  | $darkgray = imagecolorallocate($image, 0x50, 0x50, 0x50);
 | 
      
        | 40 | 152 | ryan | 
 | 
      
        | 41 | 145 | ryan | srand((double)microtime()*1000000);
 | 
      
        | 42 | 152 | ryan | 
 | 
      
        | 43 | 145 | ryan | for ($i = 0; $i < 30; $i++) {
 | 
      
        | 44 |  |  |   $x1 = rand(0,120);
 | 
      
        | 45 |  |  |   $y1 = rand(0,30);
 | 
      
        | 46 |  |  |   $x2 = rand(0,120);
 | 
      
        | 47 |  |  |   $y2 = rand(0,30);
 | 
      
        | 48 |  |  |   imageline($image, $x1, $y1, $x2, $y2 , $gray);
 | 
      
        | 49 |  |  | }
 | 
      
        | 50 | 152 | ryan | 
 | 
      
        | 51 | 145 | ryan | for ($i = 0; $i < 5; $i++) {
 | 
      
        | 52 |  |  | $cnum[$i] = rand(0,9);
 | 
      
        | 53 |  |  | }
 | 
      
        | 54 | 152 | ryan | 
 | 
      
        | 55 | 145 | ryan | for ($i = 0; $i < 5; $i++) {
 | 
      
        | 56 |  |  |  $fnt = rand(3,5);
 | 
      
        | 57 |  |  |  $x = $x + rand(12 , 20);
 | 
      
        | 58 |  |  |  $y = rand(7 , 12);
 | 
      
        | 59 |  |  |  imagestring($image, $fnt, $x, $y, $cnum[$i] , $darkgray);
 | 
      
        | 60 |  |  | }
 | 
      
        | 61 | 152 | ryan | 
 | 
      
        | 62 | 145 | ryan | $digit = "$cnum[0]$cnum[1]$cnum[2]$cnum[3]$cnum[4]";
 | 
      
        | 63 | 152 | ryan | 
 | 
      
        | 64 |  |  | session_start();
 | 
      
        | 65 |  |  | $_SESSION['captcha'] = $digit;
 | 
      
        | 66 |  |  | 
 | 
      
        | 67 | 145 | ryan | header('Content-type: image/png');
 | 
      
        | 68 |  |  | imagepng($image);
 | 
      
        | 69 |  |  | imagedestroy($image);
 | 
      
        | 70 |  |  | 
 | 
      
        | 71 |  |  | ?>
 |