CAPTCHA by own strength: Contact form

Tags: ,

As it is known, the contact form in Joomla! can be used easily for automatic delivery of a spam (that is, instead of a e-mails database, it is quite enough to have a database of the sites created using Joomla!). To be protected from this, we’ll add CAPTCHA on contact form. As well as in previous article (CAPTCHA by own strength: Backend login form), we’ll use “kcaptcha” script, though it is possible to embed any other captcha-script in the same way.

1. In /components/com_contact/contact.html.php in function _writeEmailForm we add an output of a security image and a field for input of a code (after line 694):

			<?php echo(_EMAIL_A_COPY); ?>
		</label>
	<?php
}
?>
<!--BEGIN PATCH -->
<?php session_start(); ?><br />
<img src="/kcaptcha/index.php?<?php echo session_name()?>=<?php echo session_id()?>"
 alt="Turn on pictures showing" />
<br />
<label for="contact_captcha">
Enter the code shown:
</label>
<br />
<input type="text" name="captcha" id="contact_captcha" value=""
 size="30" maxlength="10" />
<!--END PATCH -->
<br />
<br />

2. We add in/components/com_contact/contact.php in function sendmail check of correctness of the entered code (line 382):

$bannedText 	= $mparams->get( 'bannedText', 	'' );
$sessionCheck 	= $mparams->get( 'sessionCheck', 1 );
 
// BEGIN PATCH
session_start();
if(!isset($_SESSION['captcha_keystring']) ||
   $_SESSION['captcha_keystring']!==$_POST['captcha']){
	unset($_SESSION['captcha_keystring']);
	mosErrorAlert('You need to enter the code shown.');
}
unset($_SESSION['captcha_keystring']);
// END PATCH
 
// check for session cookie
if  ( $sessionCheck ) {

Here it is possible to download patch files for the Joomla! 1.0.12 (archive without kcaptcha script!).

Related Posts

16 Responses to “CAPTCHA by own strength: Contact form”

Pages: [1] 2 » Show All

  1. 1
    Michael Says:

    Hi,

    is there a chance to get this coding running in Joomla 1.5 beta, too? I did not try it myself nor did a look at the coding (I’m no PHP expert).

    Thx,
    Michael

  2. 2
    Physicist Says:

    It is a tiny bit difficult to make this in Joomla1.5 (because of clearing $_SESSION on Joomla start).
    But I hope I solve this problem.

  3. 3
    Physicist Says:

    Try captcha-contact-form patch for Joomla! 1.5. Write me about any problem, please.

  4. 4
    Viet4777 Says:

    I just installed on my website at:
    http://luyenkim.net/home9/index.php?option=com_contact&Itemid=88889198

    It works well, but there is a small bug is: when you entered a wrong code then you re-entered a right code it sitill noticed a wrong code. I must refresh the browser then enter right code It will work.

    How we can continue incase you entered wrong code the right code will be OK.

    My Joomla system: J 1.0.13 & PHP 5.xx on WIndows server.

    Thanks for useful patch.
    Viet

  5. 5
    Physicist Says:

    Viet4777:
    Probably it happens because your browser caches the old image and shows it instead of new (after entering a wrong code the image should exchange!).

  6. 6
    brimba Says:

    Please note that the 1.5 patch for joomla is not working (even with legacy ON)Fatal error: Class jsite: Cannot inherit from undefined class japplication in /home/public_html/includes/application.php on line 27Tested on J1.5 (RC3 and on Nightly build dated 10th Nov 2006.)Thanks

  7. 7
    Physicist Says:

    Well, since July 18th it has passed a lot of time. I think when stable version 1.5 will be released, I can describe work with CAPTCHA in it.

  8. 8
    spencer Says:

    I was hoping that a solution to adding Captcha to the contact form for 1.5 was found. Any luck?

    Thanks!

  9. 9
    A Says:

    Sorry for asking because I am a beginner but how do you embed the kcapthca script into Joomla? and I notice that your customization is for 1.0.12., will it work for 1.0.13?

  10. 10
    Physicist Says:

    Sorry for asking because I am a beginner but how do you embed the kcapthca script into Joomla? and I notice that your customization is for 1.0.12., will it work for 1.0.13?

    Yes. It must work (there are not so many changes in Joomla!1.0.13).

Pages: [1] 2 » Show All

You can follow any responses to this entry through the RSS 2.0 feed.

Leave a Reply