Author Topic: New Captcha system integration - Help.  (Read 3843 times)

0 Members and 1 Guest are viewing this topic.

Offline batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
New Captcha system integration - Help.
« on: February 19, 2011, 12:14:07 PM »
Hi,
     I would like to integrate a new captcha script with 4image. This new captcha uses session.. so I am not able to integrate it with 4image..

I guess, the changes will not be much..  Could anyone please let me know what changes should I make to integrate it..

I am attaching the new captcha file and one working form.php  ..  I need to integrate it in my contact.php page..


1. CaptchaSecurityImages.php   file..
Code: [Select]
<?php
session_start
();

/*
* File: CaptchaSecurityImages.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Updated: 07/02/07
* Requirements: PHP 4/5 with GD and FreeType libraries
* Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php

* 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: 
* http://www.gnu.org/licenses/gpl.html
*
*/

class CaptchaSecurityImages {

var $font 'monofont.ttf';

function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible '23456789bcdfghjkmnpqrstvwxyz';
$code '';
$i 0;
while ($i $characters) { 
$code .= substr($possiblemt_rand(0strlen($possible)-1), 1);
$i++;
}
return $code;
}

function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
$code $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size $height 0.75;
$image = @imagecreate($width$height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color imagecolorallocate($image255255255);
$text_color imagecolorallocate($imagerand(140,180), rand(140,180), rand(140,180));
$noise_color imagecolorallocate($image180180180);
/* generate random dots in background */
for( $i=0$i<($width*$height)/3$i++ ) {
imagefilledellipse($imagemt_rand(0,$width), mt_rand(0,$height), 11$noise_color);
}
/* generate random lines in background */
for( $i=0$i<($width*$height)/150$i++ ) {
imageline($imagemt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox imagettfbbox($font_size0$this->font$code) or die('Error in imagettfbbox function');
$x = ($width $textbox[4])/2;
$y = ($height $textbox[5])/2;
imagettftext($image$font_size0$x$y$text_color$this->font $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}

}

$width 160;//isset($_GET['width']) ? $_GET['width'] : '160';
$height 40;//isset($_GET['height']) ? $_GET['height'] : '40';
$characters 5;//isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';

$captcha = new CaptchaSecurityImages($width,$height,$characters);

?>



2. Form.php ( works fine with this above script)
Code: [Select]
<?php 
session_start
();

if( isset(
$_POST['submit'])) {
   if( 
$_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
echo 'Thank you. Your message said "'.$_POST['message'].'"';
unset($_SESSION['security_code']);
   } else {
// Insert your code for showing an error message here
echo 'Sorry, you have provided an invalid security code';
   }
} else {
?>


<form action="form.php" method="post">
<label for="name">Name: </label><input type="text" name="name" id="name" /><br />
<label for="email">Email: </label><input type="text" name="email" id="email" /><br />
<label for="message">Message: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br />
<img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br />
<label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" /><br />
<input type="submit" name="submit" value="Submit" />
</form>

<?php
}
?>



3. My contact.php file which needs to be modified to integrate it..
Code: [Select]
<?php 
/************************************************************************** 
 *                                                                        * 
 *    4images - A Web Based Image Gallery Management System               * 
 *    ----------------------------------------------------------------    * 
 *                                                                        * 
 *             File: contact.php                                          * 
 *        Copyright: (C) 2002  - 2010 Jan Sorgalla                        * 
 *            Email: jan@4homepages.de                                    * 
 *              Web: http://www.4homepages.de                             * 
 *    Scriptversion: 1.7.7                                                * 
 *                                                                        * 
 *    Never released without support from: Nicky (http://www.nicky.net)   * 
 *                                                                        * 
 ************************************************************************** 
 *                                                                        * 
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       * 
 *    bedingungen (Lizenz.txt) für weitere Informationen.                 * 
 *    ---------------------------------------------------------------     * 
 *    This script is NOT freeware! Please read the Copyright Notice       * 
 *    (Licence.txt) for further information.                              * 
 *                                                                        * 
 *************************************************************************/ 

$main_template "contact"

define('GET_CACHES'1); 
define('ROOT_PATH''./'); 
define('MAIN_SCRIPT'__FILE__);
include(
ROOT_PATH.'global.php'); 
require(
ROOT_PATH.'includes/sessions.php'); 
$user_access get_permission();
include(
ROOT_PATH.'includes/page_header.php'); 
$txt_clickstream "Contact"

if (
$action == "") {
  
$action "mailform"



$content ""

$sendprocess 0

if (
$action == "emailSiteOwner") { 
 
  
$error 0
  
  
$mail_to = (isset($_POST['emails'])) ? $_POST['emails'] : $config['site_email'];
  
$sender_name stripslashes(trim($_POST['sender_name'])); 
  
$sender_email stripslashes(trim($_POST['sender_email'])); 

  
$subject un_htmlspecialchars(trim($HTTP_POST_VARS['subject'])); 
  
$message un_htmlspecialchars(trim($HTTP_POST_VARS['message'])); 
  
  
$captcha = (isset($HTTP_POST_VARS['security_code'])) ? un_htmlspecialchars(trim($HTTP_POST_VARS['security_code'])) : "";


if (
$sender_name == "" || $sender_email == "" || $subject == "" || $message == "") { 
    
$msg $lang['lostfield_error']; 
    
$sendprocess 1
    
$error 1
  } 
  
 
$check "/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,4})$/";

if(!isset(
$sender_email) OR $sender_email == "" OR !preg_match($check,$sender_email))
   {
   
$msg .= (($msg != "") ? "<br />" "").$lang['invalid_email_format']; 
    
$sendprocess 1
    
$error 1
   }

echo 
"eststtstss ==> " .$session_info['security_code'];
  
if (
$captcha_enable_contact && !captcha_validate($captcha)) {
  $msg .= (($msg != "") ? "<br />" "").$lang['captcha_required'];
  $error 1;
    }

if (!
$error) { 
    
$sender_user_name $sender_name
    
$sender_user_email $sender_email

    
// Start Emailer 
    
include(ROOT_PATH.'includes/email.php'); 
    
$site_email = new Email(); 
    
$site_email->set_from($sender_user_email$sender_user_name); 
    
$site_email->set_to($mail_to); 
    
$site_email->set_subject($subject);
    
$site_email->register_vars(array( 
    
"sender_user_name" => $sender_user_name
    
"sender_user_email" => $sender_user_email
    
"message" => $message
    
"site_name" => $config['site_name'
    )); 
    
    
$site_email->set_body("mailform_message"$config['language_dir']); 
    
$site_email->send_email(); 
    
$msg 'Email has been sent. I will contact you as soon as possible. Thank you !!' 

  } 
  else { 
    
$action "mailform"
  } 


if (
$action == "mailform") { 
  if (!
$sendprocess) { 
    
$subject ""
    
$message ""
  } 
  
  
$sender_name = ($user_info['user_level'] != GUEST) ? $user_info['user_name'] : ""
  
$sender_email = ($user_info['user_level'] != GUEST) ? $user_info['user_email'] : ""
  
    
$site_template->register_vars(array( 
      
"sender_name" => $sender_name
      
"sender_email" => $sender_email,
      
"url_form" => $site_sess->url(ROOT_PATH."contact.php"),
      
"subject" => htmlspecialchars($subject), 
      
"message" => htmlspecialchars($message), 
      
"captcha_contact" => (bool)$captcha_enable_contact,
      
"lang_captcha" => $lang['captcha'],
      
"lang_captcha_desc" => $lang['captcha_desc'],
      
"lang_mail_to" => $lang['mail_to'],
      
"lang_your_name" => 'Name:'
      
"lang_your_mail" => 'Email:'
      
"lang_subject" => 'Subject:'
      
"lang_message" => 'Message:'
      
"lang_submit" => $lang['submit'], 
      
"lang_reset" => $lang['reset'],
    )); 
    
$content $site_template->parse_template("contact_mailform"); 


//----------------------------------------------------- 
//--- Clickstream ------------------------------------- 
//----------------------------------------------------- 
$clickstream "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'].$txt_clickstream."</span>"


//----------------------------------------------------- 
//--- Print Out --------------------------------------- 
//----------------------------------------------------- 
$site_template->register_vars(array( 
  
"content" => $content
  
"msg" => $msg
  
"clickstream" => $clickstream
)); 

$site_template->print_template($site_template->parse_template($main_template)); 

include(
ROOT_PATH.'includes/page_footer.php'); 
?>


I have already modified my contact_form.html template file to include this..
Code: [Select]
    {if captcha_contact}
<tr>
        <td width="80" valign="top"><b><!--{lang_captcha}--><label for="security_code">Security Code: </label></b></td>
<!--         <td>{recaptcha}</td> -->
<td><img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br /><br />
<input id="security_code" name="security_code" type="text" /><br />
</td>
    </tr>
   {endif captcha_contact}


I have also attached required .ttf file here.

Any help will be appreciated..

Thank you
batu544

Offline batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
Re: New Captcha system integration - Help.
« Reply #1 on: February 23, 2011, 06:49:51 AM »
Hi,
     Could anyone please look into this issue..  :roll: ??

Thank you
batu544