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

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

  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).

  11. 11
    kn Says:

    this is perfect, no need for those 3rd party modules/components that annoyingly require a bunch of extra ones as a base, plus now i know where i need to edit the code to adjust positions/sizes/titles/etc

  12. 12
    Insanoff Says:

    How i may this with loginform?

  13. 13
    Henk Says:

    Thanks very much - this resolved an issue with a spammer I had on one site. Worked great in the contact form on a joomla 1.0.15 installation.

    Cheers and thanks again

  14. 14
    Henk Says:

    Can we get an updated set of instructions for joomla 1.5?

    I tried but failed miserably.

  15. 15
    Rick Says:

    Thank You Very Much!

    I added Captcha to a commercial site that was being pounder by a spammer…

    Worked perfectly first time… the step by step instructions are great. Is there somewhere I can make a donation for your time? 
    Truly greatful,Rick

  16. 16
    Nirav Says:

    Hey can you please tell me the steps and files to be modified .. I tried above contact.php and contact.html.php but it did not work in my joomla 10.0.15 . what am I suppose to do with Patch you have provided and kcaptcha script. where to place this kcatpcha folder.
    Please let me know.

  17. 17
    Sagar Says:

    can we remove the website name(www.captcha.ru) in the captcha image?

  18. 18
    Physicist Says:

    Sagar, there is special parameter in kcaptcha configuration file.

  19. 19
    Sagar Says:

    thanks physicist. Do we have an option of reloading the captcha, if the user feels it difficult to read?

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

Leave a Reply