How to prevent spam on your pligg site.

The main problem with pligg sites are spam. Few weeks earlier i started my first pligg site and my experience was really bad . each day i got almost hundreds of spam. The best way to prevent spam is to add a captcha in your submit pages. Here i am going to explain about configuring captcha for your pligg submit page. First you need to edit your submit_step_1.tpl file which you can find under root/templates/ and inside your template directory. Just add the following code as shown in the below screenshot

{php}
require_once('recaptchalib.php');
$publickey = "6LcqcAsAAAAAAEFc2PXs78WwHuuY3LDnL1F0V332"; // you got this from the signup page
echo recaptcha_get_html($publickey);
{/php}

Now just go to submit.php , this file you can find under your root folder. Just copy pastre the following code as shown in the screen shot.

//captcha

        require_once('recaptchalib.php');
        // Get a key from http://recaptcha.net/api/getkey
        $publickey = "6LcqcAsAAAAAAEFc2PXs78WwHuuY3LDnL1F0V332";
        $privatekey = "6LcqcAsAAAAAAMilB7N7ZkGut2yygvurK4waJ-o2";

        # the response from reCAPTCHA
        $resp = null;
        # the error code from reCAPTCHA, if any
        $error = null;

        # was there a reCAPTCHA response?
        if ($_POST["recaptcha_response_field"]) {
                $resp = recaptcha_check_answer ($privatekey,
                                                $_SERVER["REMOTE_ADDR"],
                                                $_POST["recaptcha_challenge_field"],
                                                $_POST["recaptcha_response_field"]);

                if ($resp->is_valid) {

                } else {
                        # set the error code so that we can display it
                        $error = $resp->error;

                }
        }    

	//if (!$resp->is_valid) { // if incorrect captcha code was entered

      if (!$resp->is_valid && !isset($_GET['id'])) { // if incorrect captcha code was entered
        // echo "
Enter Correct Captcha!
"; //$main_smarty->assign('register_error_text', "test"); //$main_smarty->display($the_template . '/submit_errors.tpl'); // return; // if (!$resp->is_valid) { // if incorrect captcha code was entered $main_smarty->assign('submit_error', 'badcode'); $main_smarty->assign('tpl_center', $the_template . '/captcha'); $main_smarty->display($the_template . '/pligg.tpl'); return; } // fin capthca

Now Just Download the latest reCaptcha library from here and upload to your “root”.

Now just go to submit page , you will get a captcha box  shown like below.

Thats all… Enjoy

Post By Editor (2,827 Posts)

Website: →

Connect