Location: PHPKode > projects > Fusion Board > v_1-0-0/includes/register_confirm.inc.php
<?php
/**********************************************************************/
/*                 Powered By Fusion Board V 1.0.0
/**********************************************************************/
/* Author:               Keven Brochu
/* Copyright:            © 2004/2005 - KevBrok, The Dynamic Fusion Team
/* Web:                  http://www.dynamic-fusion.net
/* E-mail:               hide@address.com
/* Begin:                03 Feb 2005 19:30 GMT
/* Last Update:          09 Feb 2005 00:25 GMT
/* Fusion Board Version: 1.0.0
/* File Version:         1.0.0
/**********************************************************************/
/* Visit Dynamic-Fusion website for details, updates, support and more.
/**********************************************************************/
/* includes/register_confirm.inc.php
/* Confirm image for registration. This file create a new confirm code,
/* save it in the database and show it in a PHP image. GD is requied.
/**********************************************************************
/* Please send me a e-mail if you want to use this code.
/**********************************************************************/

if ( !defined('FILE_ACCESS') ) exit;

/*
* Make sure that the visual confirmation is ON and the GD extension is loaded
*/
if ( !$config['REG_VISUAL_CONFIRMATION'] || !extension_loaded('gd') )
{
	exit;
}

/*
* Check if all requied functions are there
*/
$gd_ext = get_extension_funcs('gd');
$gd_ext = array_flip($gd_ext);
if ( !isset($gd_ext['imagepng'])
  || !isset($gd_ext['imagecreatetruecolor'])
  || !isset($gd_ext['imagecolorallocate'])
  || !isset($gd_ext['imagefill'])
  || !isset($gd_ext['imageline'])
  || !isset($gd_ext['imagettftext' ]) )
{
	exit;
}

/*
* Define the charlist; DO NOT change this string
*/
$charlist = 'OEKLUAPDZF8419VT7SJIC52WQHGR30NXYBM6';

/*
* Width and height
* Be careful when changing the height; The chars may not line-up correctly and make a verry weird image.
* It's advised to keep these sizes.
*/
$width = 122;
$height = 32;

/*
* Create a new code
*/
$code = '';
$chars_count = strlen( $charlist ) - 1;
mt_srand( ( double ) microtime() * 1000000 );

for ( $i = 0; $i < 7; $i++ )
{
	if ( $i <> 0 )
	{
		$code .= '.';
	}

	$code .= round( mt_rand( 0, $chars_count ) );
}

/*
* Save this code in database
*/
$SQL -> query( $QUERIES -> set_confirm_code( $code, $SESSION -> infos['user_ip'] ) );

$SQL -> close(); // Close SQL connection
unset($SQL);

/*
* Split values and create a new blank image
*/
$imgchar = explode( '.', $code );
$curr_img = imagecreatetruecolor( $width, $height );

/*
* Define some colors
*/
$white = imagecolorallocate( $curr_img, 255, 255, 255 ); // White
$gray  = imagecolorallocate( $curr_img, 192, 192, 192 ); // Gray
$dgray = imagecolorallocate( $curr_img, 128, 128, 128 ); // Dark gray
$black = imagecolorallocate( $curr_img,   0,   0,   0 ); // Black
$red   = imagecolorallocate( $curr_img, 255,   0,   0 ); // Red

/*
* Set background color
*/
imagefill( $curr_img, 0, 0, $white );

/*
* Draw lines
*/
for ( $w = 0; $w <= $height; $w += 5 )
{
	imageline( $curr_img, 0, $w, $width -1, $w, $gray );
}
for ( $h = 0; $h <= $width; $h += 5 )
{
	imageline( $curr_img, $h, 0, $h, $height -1, $gray );
}

/*
* Add some 3D effects
*/
imageline( $curr_img, 0, $height - 1, $width - 1, $height - 1, $dgray );
imageline( $curr_img, $width - 1, 0, $width - 1, $height - 1, $dgray );

/*
* Write the text;
* Define chars positions (Do a random wave effect)
*/
$rand_start_x = round( rand( 4, $width  - 104 ) );
$char_top[0]  = round( rand( 4, $height -  22 ) );
$char_top[3]  = round( rand( 4, $height -  22 ) );
$char_top[6]  = round( rand( 4, $height -  22 ) );

$char_top[1]  = $char_top[2] = ( $char_top[0] > $char_top[3] ) ?
	round( $char_top[0] - $char_top[3] ) : round( $char_top[3] - $char_top[0] );

$char_top[4]  = $char_top[5] = ( $char_top[3] > $char_top[6] ) ?
	round( $char_top[3] - $char_top[6] ) : round( $char_top[6] - $char_top[3] );

/*
* Define font file
*/
$font_file = ROOT_PATH . 'html/confirm.ttf';

for ( $t = 0; $t < 7; $t++ )
{
	$char_left = $rand_start_x + ( $t * 15 );

	/*
	* Wich color we will use?
	* Black for letters, Red for numbers
	*/
	$color = ( is_numeric( $charlist[$imgchar[$t]] ) ) ?
		$red : $black;

	/*
	* Write the char with the defined position
	* And using the confirm font (Font is Arial Black, a readable font)
	*/
	imagettftext( $curr_img, 11, 0, $char_left, $char_top[$t] + 14, $color, $font_file, $charlist[$imgchar[$t]] );
}

/*
* Output
*/
header('Content-type: image/png');
header('Cache-control: no-cache, no-store');
imagepng($curr_img);

exit;
?>
Return current item: Fusion Board