Location: PHPKode > projects > Gnew > Gnew-2013.1/users/captcha.php
<?php
// -----------------------------------------------------------------------------
// $Id: captcha.php 618 2013-03-18 14:37:53Z raoul $
//
// Copyright (C) 2013 Raoul Proença
// License: GNU GPL version 3 (see copying.txt file)
// Website: http://www.gnew.fr/
// -----------------------------------------------------------------------------
// 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 3 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, see <http://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------

include('./../includes/common.php');

if (function_exists('imagecreatefrompng') && $image = @imagecreatefrompng('./../images/users/captcha.png'))
{
    $font = './../includes/ttf/pointfree.ttf';
    $i = 1;
    $string = $_SESSION['user_captcha'];
    for ($j = 0; $j < 6; $j++)
    {
        $red = mt_rand(0, 192);
        $green = mt_rand(0, 192);
        $blue = mt_rand(0, 192);
        $color = imagecolorallocate($image, $red, $green, $blue);

        imagettftext($image, 16, 0, $i, 17, $color, $font, $string{$j});
        $i += 13;
    }

    // For transparency
    imagealphablending($image, true);
    imagesavealpha($image, true);

    header('Content-type: image/png');
    imagepng($image);
    imagedestroy($image);
}
else
{
    header('Content-type: image/png');
    readfile('./../images/users/captcha_without_gd.png');
    $_SESSION['user_captcha'] = 64;
}

// This file is called after register.php. Since we don't call page_footer()
// function here, we need to close the session first and then the database.
session_write_close();
$GLOBALS['sql']->close();

?>
Return current item: Gnew