This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Upgrading Recaptcha Form
#1

Hi,  I am running a Commentics script from several years ago.  On my site I am now getting the message on the comments form "reCAPTCHA V1 IS SHUTDOWN" and it gives me a link to get new keys.  I got new keys and entered them in the Commentics admin area, but the comments form still says the same thing.  What shall I do?  I looked into doing a Commentics upgrade, but the upgrades page only had options to go from 3.0 forward, my version is v2.2. Can I upgrade to current script from v2.2?
Reply
#2

Hi I provided these instructions to someone on Commentics v2.4 to update their reCaptcha. It should be the same if not similar.

Step 1

Open this file: /includes/template/form.php

Replace this:

Code:
<div class="cmtx_recaptcha"><?php
if ((cmtx_setting('recaptcha_public_key') == '') || (cmtx_setting('recaptcha_private_key') == '')) {
    echo "<span class='cmtx_recaptcha_no_key'>" . CMTX_RECAPTCHA_NO_KEY . "</span>.";
} else {
    require_once $cmtx_path . 'includes/recaptcha/recaptchalib.php';
    $cmtx_recaptcha_public_key = cmtx_setting('recaptcha_public_key');
    echo recaptcha_get_html($cmtx_recaptcha_public_key);
} ?>
</div>

With this:

Code:
<div class="cmtx_recaptcha">
    <div class="cmtx_container cmtx_recaptcha_container">
        <div id="g-recaptcha" class="g-recaptcha" data-sitekey="<?php echo cmtx_setting('recaptcha_public_key'); ?>" data-theme="light" data-type="image" data-size="normal"></div>
    </div>
</div>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>

Step 2

Open this file: /includes/app/processor.php

Replace this:

PHP Code:
<?php 
//ReCaptcha
if (cmtx_setting('enabled_captcha') && cmtx_setting('captcha_type') == 'recaptcha') {
if (
cmtx_setting('recaptcha_public_key') == '' || cmtx_setting('recaptcha_private_key') == '') {} else {
if (
function_exists('fsockopen') && is_callable('fsockopen')) {
if ((!isset(
$_POST['recaptcha_challenge_field']) || !isset($_POST['recaptcha_response_field']))) {
cmtx_error(CMTX_ERROR_MESSAGE_NO_CAPTCHA); //reject user for entering no captcha value
} else {
$cmtx_captcha = trim($_POST['recaptcha_response_field']); //get and trim entered captcha value
if (empty($cmtx_captcha)) { //if no captcha value entered
cmtx_error(CMTX_ERROR_MESSAGE_NO_CAPTCHA); //reject user for entering no captcha value
} else { //if captcha value entered
require_once $cmtx_path . 'includes/recaptcha/recaptchalib.php'; //load captcha script
$cmtx_recaptcha_private_key = cmtx_setting('recaptcha_private_key');
$cmtx_recaptcha_response = recaptcha_check_answer($cmtx_recaptcha_private_key, $cmtx_ip_address, $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
if (!
$cmtx_recaptcha_response->is_valid) { //if entered captcha value invalid
cmtx_error(CMTX_ERROR_MESSAGE_WRONG_CAPTCHA); //reject user for entering wrong captcha value
} else {
if (
cmtx_session_set()) { //if there's a session
$_SESSION['cmtx_captcha'] = cmtx_setting('session_key'); //add captcha completion to session
}
}
}
}
}
}
}

With this:

PHP Code:
<?php 
//ReCaptcha
if (cmtx_setting('enabled_captcha') && cmtx_setting('captcha_type') == 'recaptcha') {
if (
cmtx_setting('recaptcha_public_key') == '' || cmtx_setting('recaptcha_private_key') == '') {} else {
if (
function_exists('fsockopen') && is_callable('fsockopen')) {
if (isset(
$_POST['g-recaptcha-response'])) {
$captcha = $_POST['g-recaptcha-response'];

if (
$captcha) {
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . cmtx_setting('recaptcha_private_key') . '&response=' . $captcha . '&remoteip=' . $cmtx_ip_address);

$response = json_decode($response);

if (
$response->success === false) {
cmtx_error('You didn\'t pass the captcha test. Please try again.');
} else {
if (
cmtx_session_set()) { //if there's a session
$_SESSION['cmtx_captcha'] = cmtx_setting('session_key'); //add captcha completion to session
}
}
} else {
cmtx_error('Please tick the checkbox inside the captcha');
}
} else {
cmtx_error('Please tick the checkbox inside the captcha');
}
}
}
}

Have you completed the interview?
Reply
#3

Excellent! Thank you. Is it possible to upgrade to the current v3.3 from v2.2 though?
Reply
#4

I successfully replaced the code as suggested, however there was a problem.  It removed everything from the website that was after where the captcha form would be as if there was an open tag somewhere, but I looked and couldn't find one.  There was no captcha form either.  The div class names are different as well, where above it is written as div class="cmtx_recaptcha" in my file it is written as "cmtx_captcha_field".  I replaced the div class name but it didn't make it work.

Here is the code that is to be replaced in Step 1 as written in my v2.2 file:

<div class="cmtx_captcha_field">
<?php
if (($cmtx_settings->recaptcha_public_key == "") || ($cmtx_settings->recaptcha_private_key == "")) {
echo "<span class='cmtx_no_recaptcha_key'>" . CMTX_RECAPTCHA_NO_KEY . "</span>.";
} else {
require_once $cmtx_path . "includes/recaptcha/recaptchalib.php";
$cmtx_recaptcha_public_key = $cmtx_settings->recaptcha_public_key;
echo recaptcha_get_html($cmtx_recaptcha_public_key);
}
?>
</div>


I've isolated the problem to being something to do with the data-sitekey <?php echo cmtx_setting('recaptcha_public_key'); ?> when I remove that code the website returns to normal, of course the captcha form doesn't appear.

If you view the webpage source after it has loaded it literally ends like this:


<div class="cmtx_recaptcha">
    <div class="cmtx_container cmtx_recaptcha_container">
        <div id="g-recaptcha" class="g-recaptcha" data-sitekey="


Clearly, there is a problem with the data-sitekey.  I tried replacing the data-sitekey tag "recaptcha_public_key" with "cmtx_recaptcha_public_key" as it seems to be written in my v2.2 file, but that didn't work either.

EDIT: I also tried changing the tag "cmtx_setting" with "cmtx_settings" as it appears to be written in the v2.2 file, but that made no difference either.

Anyways, don't trouble yourself too much with this.  I'll be glad and would actually prefer to just upgrade to the current commentics script if possible.
Reply
#5

Sure here are the upgrade instructions for the older versions:

http://web.archive.org/web/2017013122580...rg/upgrade

Have you completed the interview?
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by Steven
28-Jan-2023, 01:16 PM
Last Post by Steven
25-Jun-2020, 08:10 AM
Last Post by bahar
16-Nov-2015, 10:07 AM
Last Post by Ron
05-Jun-2014, 08:34 PM
Last Post by DjViper
02-Dec-2012, 12:10 PM
Last Post by Static
29-Jan-2011, 10:51 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)