Location: PHPKode > projects > MGB OpenSource Guestbook > mgb-0.6.9.2/includes/captcha.inc.php
<?php
	/*
	MGB 0.6.x - OpenSource PHP and MySql Guestbook
	Copyright (C) 2004 - 2011 Juergen Grueneisl - http://www.m-gb.org/

	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.
	*/

	// =============== //
	// captcha.inc.php //
	// =============== //
	//
	// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

	//Header ("Content-type: image/png");

	require ("config.inc.php");
	require ("functions.inc.php");
	require ("load_settings.inc.php");

	// randomly choose a background for the captcha
	$captcha_dir = "../images/captchas/";
	if (is_dir($captcha_dir))
		{
		if ($dir = @opendir($captcha_dir))
			{
			$filecounter = 0;
			while(($file = @readdir($dir)) !== false)
				{
				$filecounter++;
				}
			@closedir($file);
			}
		}
	// counting starts when opening directories. there are two directories, so substract 2
	$filecounter = $filecounter - 2;

	// if the captcha-background doesn't exist, get a new random number
	$captcha_randombg = rand(1, $filecounter);
	if (!file_exists("../images/captchas/captchabg".$captcha_randombg.".png"))
		{
		echo "Background #".$captcha_randombg." does not exist!";
		die();
		}
	$captcha_img = imagecreatefrompng ("../images/captchas/captchabg".$captcha_randombg.".png");

	if ($settings['captcha_method'] == 0)
		{
		// get code from database
		$sql = "SELECT `code` FROM ".$db['prefix']."captcha";
		$link = @mysql_connect($db['hostname'], $db['username'], $db['password']) or die ("(captcha.inc.php) Error, line 63: ".mysql_error());
		mysql_select_db($db['dbname'], $link) or die ("(captcha.inc.php) Error, line 64: ".mysql_error());
		$result = mysql_query($sql, $link) or die ("(captcha.inc.php) Error, line 65: ".mysql_error());

		$captcha = @mysql_fetch_array($result);
		$captcha_text = $captcha['code'];

		$x = $settings['captcha_coords_x']; // x-coordinate where to start the text in the image
		$y = $settings['captcha_coords_y'];; // y-coordinate where to start the text in the image
		$textcolor = "0x00".$settings['captcha_color']; // color of text
		$angle = rand($settings['captcha_angle_1'], $settings['captcha_angle_2']); // random value of the text angle
		imagettftext($captcha_img, 22, $angle, $x, $y, $textcolor, "../fonts/akoom.ttf", $captcha_text);
		}
	else
		{
		// get code from database
		$sql = "SELECT `math` FROM ".$db['prefix']."captcha_math";
		$link = @mysql_connect($db['hostname'], $db['username'], $db['password']) or die ("(captcha.inc.php) Error, line 80: ".mysql_error());
		mysql_select_db($db['dbname'], $link) or die ("(captcha.inc.php) Error, line 81: ".mysql_error());
		$result = mysql_query($sql, $link) or die ("(captcha.inc.php) Error, line 82: ".mysql_error());

		$captcha = @mysql_fetch_array($result);
		$captcha_text = $captcha['math'];

		$x = $settings['captcha_coords_x']; // x-coordinate where to start the text in the image
		$y = $settings['captcha_coords_y'];; // y-coordinate where to start the text in the image
		$textcolor = "0x00".$settings['captcha_color']; // color of text
		$angle = rand($settings['captcha_angle_1'], $settings['captcha_angle_2']); // random value of the text angle
		imagettftext($captcha_img, 18, $angle, $x, $y, $textcolor, "../fonts/acidic.ttf", $captcha_text);
		}

	// The font "akoom.ttf" used in here is copyrighted by http://veredgf.fredfarm.com/.
	// It is NOT released under GNU/GPL. It's Freeware. This means you can use and
	// share it for free but you may NOT sell it!

	imagepng($captcha_img);
	imagedestroy($captcha_img);
?>
Return current item: MGB OpenSource Guestbook