<?php
/*
Copyright 2007, Arpan Steven Yonzon
Link: http://grandfinale2002.christian.net/
This file is part of captchaCOLA.
captchCOLA is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
captchaCOLA 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 captchaCOLA. If not, see <http://www.gnu.org/licenses/>.
============================================================
Application Description
============================================================
A free open source Spam CAPTCHA System designed
Application Name: captchaCola
Version: 1.0
Date created: August 2007
License: --LGPL.txt--
------------------------------------------------------------
About this page
------------------------------------------------------------
Defines the settings for the captchaCola class
*/
define('APPNAME', 'captchaCola');
/*----------------------------------------------------------
Error Reporting: Should be OFF for production servers.
------------------------------------------------------------
*/
error_reporting(0);//uncomment for testing.
/*
---------------------------------------------------------------
CaptchaCola language settings (string)
---------------------------------------------------------------
*/
$language = "english";
/*
---------------------------------------------------------------
Directory Settings for captchaCola
---------------------------------------------------------------
Root directory settings for captchaCola
Path/to/alphabet/image/files (array)(string)
---------------------------------------------------------------
*/
$captcha_dir = dirname(__FILE__); //root dir for captchaCola
//swapping directory separator to Unix style for consistency
$captcha_dir = str_replace("\\", "/", $captcha_dir);
define('CAPTCHADIR', $captcha_dir . '/');
/*This is where the images reside. Rename if your directory is
different from default "images" */
$image_dir = "images";
if (is_dir(CAPTCHADIR . $image_dir))
{
define('IMAGEDIR', CAPTCHADIR . $image_dir . '/');
}
else
{
exit("Could not locate image directory: <b>'{$image_dir}'</b>.");
}
/*
Set path/to/alphabet/pictures/
Other language users need to set their alphabet directory here.
Be sure to create/name the defined directory.
*/
$alphabet_location = array (
"a" => IMAGEDIR . "a/",
"b" => IMAGEDIR . "b/",
"c" => IMAGEDIR . "c/",
"d" => IMAGEDIR . "d/",
"e" => IMAGEDIR . "e/",
"f" => IMAGEDIR . "f/",
"g" => IMAGEDIR . "g/",
"h" => IMAGEDIR . "h/",
"i" => IMAGEDIR . "i/",
"j" => IMAGEDIR . "j/",
"k" => IMAGEDIR . "k/",
"l" => IMAGEDIR . "l/",
"m" => IMAGEDIR . "m/",
"n" => IMAGEDIR . "n/",
"o" => IMAGEDIR . "o/",
"p" => IMAGEDIR . "p/",
"q" => IMAGEDIR . "q/",
"r" => IMAGEDIR . "r/",
"s" => IMAGEDIR . "s/",
"t" => IMAGEDIR . "t/",
"u" => IMAGEDIR . "u/",
"v" => IMAGEDIR . "v/",
"w" => IMAGEDIR . "w/",
"x" => IMAGEDIR . "x/",
"y" => IMAGEDIR . "y/",
"z" => IMAGEDIR . "z/",
"0" => IMAGEDIR . "0/",
"1" => IMAGEDIR . "1/",
"2" => IMAGEDIR . "2/",
"3" => IMAGEDIR . "3/",
"4" => IMAGEDIR . "4/",
"5" => IMAGEDIR . "5/",
"6" => IMAGEDIR . "6/",
"7" => IMAGEDIR . "7/",
"8" => IMAGEDIR . "8/",
"9" => IMAGEDIR . "9/"
);
/*
---------------------------------------------------------------
Captcha type: Output image settings
---------------------------------------------------------------
Set the type of output image that captchaCola will generate
Parameters accepted
text - for text only captcha image
picto - for pictograms (default)
---------------------------------------------------------------
Note: parameter will default to "picto" if incorrectly set
*/
$cap_type = "picto";
/*
---------------------------------------------------------------
Security code type: Output security code settings
---------------------------------------------------------------
Set the type of security code that captchaCola will generate
Parameters accepted
alpha - for alphabet only code (default)
number - for numeric only code
both - for alpha-numeric code //safest option but could be confusing to some users
---------------------------------------------------------------
Note: parameter will default to "alpha" if incorrectly set
*/
$code_type = "alpha";
/*
---------------------------------------------------------------
Font settings (integer)
---------------------------------------------------------------
Alternative settings for pictograms. If an image for an alphabet
is not found, captchaCola will write an alternative text alphabet
using this font or inbuilt font if not available.
---------------------------------------------------------------
*/
$fontsize = 18; //(integer) defaults to 12 if incorrectly set
//Directory to font file. Rename if different. (Must be a sub-directory of "captcha" dir)
$font_dir = "font";
$fontname = "verdanab.ttf"; //font to use - include extension e.g: *.ttf (font must be available)
/*
---------------------------------------------------------------
Secret word (string)
---------------------------------------------------------------
A personal secret word to personalize your CAPTCHA implementation.
This is appended to the generated security code. Provides added
security. Write your own secret code.
---------------------------------------------------------------
*/
//$secret = "captchaCOLA";
/*
--------------------------------------------------------------
End of user editable settings
--------------------------------------------------------------
*/
/*
--------------------------------------------------------------
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
==============================================================
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Double-checking all parameters set by user
Warning: IF YOU DON'T KNOW WHAT YOU'RE DOING, IT IS BEST THAT
THE FOLLOWING IS LEFT ALONE.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
==============================================================
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
--------------------------------------------------------------
*/
//Double-check to see if alphabet directory exists
foreach ($alphabet_location as $alphabet_dir)
{
if (!is_dir($alphabet_dir))
{
exit("Could not locate: <b>$alphabet_dir</b>");
}
}
define('CAPTCHAFILENAME', pathinfo(__FILE__, PATHINFO_BASENAME));
define('CAPTCHAEXT', '.' . pathinfo(__FILE__, PATHINFO_EXTENSION));
//double-check for correct parameters
if (!is_string($cap_type))
{
$cap_type = "picto";
}
elseif ((trim($cap_type) !== "picto") and (trim($cap_type) !== "text"))
{
$cap_type = "picto";
}
//double-check for correct parameters
if (!is_string($code_type))
{
$code_type = "alpha";
}
elseif ((trim($code_type) !== "alpha") and (trim($code_type) !== "number") and (trim($code_type) !== "both"))
{
$code_type = "alpha";
}
//double-check for correct parameters
if (!is_int($fontsize) or ($fontsize <= 6))
{
$fontsize = 12;
}
//check if font-file exists
if (is_dir(CAPTCHADIR . $font_dir))
{
define('FONTDIR', CAPTCHADIR . $font_dir . '/');
if (!file_exists(FONTDIR . $fontname))
{
$fontname = "";
}
else
{
$fontname = FONTDIR . $fontname;
}
}
else
{
define('FONTDIR', '');
$fontname = "";
}
//define SECRET
/*
if (!isset($secret) or $secret == "")
{
define('SECRET', 'captchaCOLA');
}
else
{
define('SECRET', $secret);
}
*/
/*
--------------------------------------------------------------
Check PHP version. This application requires PHP4 or higher.
It is meaningless to go beyond this if version does not support
GD library. Check if essential GD library is loaded.
--------------------------------------------------------------
*/
if (phpversion() < 4)
{
exit("This application requires PHP version 4 or higher. Please update!");
}
//check if GD extension is loaded
if (!extension_loaded('gd'))
{
//load gd library
$loadgd = dl('php_gd2.dll');
//above may not work if PHP is in 'safe mode'
if ($loadgd == false)
{
exit("An essential component (GD) could not be loaded. The server is probably running in <b>Safe mode</b>. Contact server admin.");
}
}
//garnish and serve
require_once(CAPTCHADIR . 'captchacola' . CAPTCHAEXT);
/*
--------------------------------------------------------------------
| Implementation
--------------------------------------------------------------------
*/
$captchaClass = new captchaCola( $language, $cap_type, $code_type, $fontname, $fontsize, $alphabet_location );
$captchaClass->create_image();
?> |