Revision: 80
http://astrospaces.svn.sourceforge.net/astrospaces/?rev=80&view=rev
Author: p3net
Date: 2007-07-30 23:36:53 -0700 (Mon, 30 Jul 2007)
Log Message:
-----------
A VERY basic CAPTCHA model
Added Paths:
-----------
trunk/functions/captcha.php
Added: trunk/functions/captcha.php
===================================================================
--- trunk/functions/captcha.php (rev 0)
+++ trunk/functions/captcha.php 2007-07-31 06:36:53 UTC (rev 80)
@@ -0,0 +1,74 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ @id: $Id$
+*********************************************************/
+class captcha
+{
+ function generate()
+ {
+ header('Content-type: image/png');
+ $chars = "abcdefghijklmnopqrstuvwxyz";
+ $chars .= strtoupper($chars) . "123456789";
+
+ $phrase = array();
+ $rotate = array();
+ $i=0;
+ while($i<7)
+ {
+ $num = rand(1,(26+26+9)-1);
+ $phrase[$i] = substr($chars, $num, 1);
+ $rotate[$i] = rand(-45, 45);
+ $i++;
+ }
+ $width = "200";
+ $height = "50";
+
+ $cap = ImageCreateTrueColor($width, $height);
+ $white = ImageColorAllocate($cap, 255, 255, 255);
+ $black = ImageColorAllocate($cap, 0, 0, 0);
+ $color = array(
+ 'red' => ImageColorAllocate($cap, 255, 0, 0),
+ 'green' => ImageColorAllocate($cap, 0, 255, 0),
+ 'blue' => ImageColorAllocate($cap, 0, 0, 255)
+ );
+ ImageFillToBorder($cap, 0, 0, $white, $white);
+
+ /* Let's create between 3 and 6 lines */
+ $line_count = rand(3, 6);
+ $a=0;
+ while($a < $line_count)
+ {
+ $col = rand(0, count($color)-1);
+ $col = $color[$col];
+ ImageLine($cap, rand(0, $width-100), rand(0, $height - 20), rand($width-100, $width), rand($height-20, $height), $col);
+ $a++;
+ }
+ /* Letters */
+ $i=0;
+ while($i < 7)
+ {
+ imagestring($cap, 31, 8*$i, 12*$1, $phrase[$i], $black);
+ $i++;
+ }
+
+ ImagePNG($cap);
+ imageDestroy($cap);
+ }
+}
+?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|