11 Mart 2018

sNews CMS Sistemi Yorum Güvenlik Kodu Eklentisi

11 Mart 2018
sNews CMS 1.7.x sisteminiz için hazırlanmış olan Captcha (güvenlik kodu) eklentisi. Spam yorumlardan korunmanızı sağlayacak oldukça faydalı bir kod betiği...



Eklenti iki rakamın toplamı şeklinde güvenlik kodu grafikleri sunuyor.

Örn: 4+6 = ?

Kodlamaya başlarken;

Tüm bu işlemleri uygulamadan önce sisteminizin yedeğini alınız...

Kodlama;

sNews.php dosyasını açın ve aşağıdaki kod betiğini bulun,

// MATH CAPTCHA
function mathCaptcha() {
$x = rand(1, 9);
$y = rand(1, 9);
$_SESSION[_SITE.'mathCaptcha-digit'] = $x + $y;
$math = '
<p><label for="calc">
* '.l('math_captcha').':
</label><br />';
$math .= $x.' + '.$y.' = ';
$math .= '
<input type="text" name="calc" id="calc" />
</p>';
return $math;
}

ve aşağıdaki kod ile değiştirin...

// MATH CAPTCHA
function mathCaptcha() {
    $my_salt = "123"; // enter your own personal salt here to ensure your images are different from everyone else's
    $my_captcha_folder = 'guvenlikkodu/'; //create this directory in the same directory as your snews.php
    $mathkey = date('d'); // new key for every day of the month, max 81 images in a day will save tons of resources on busy sites
    $x = rand(1, 9);
    $y = rand(1, 9);
    $_SESSION[_SITE.'mathCaptcha-digit'] = $x + $y;
    $math = '
        <p><label for="calc">
            * '.l('math_captcha').':
        </label><br />';
    if(!function_exists('imagecreate') || !is_dir($my_captcha_folder) || !is_writable($my_captcha_folder)) { // either php isn't configured to create images or the captcha folder doesn't exist/isn't writable so let's fall back to the standard text mathCaptcha
        $math .= $x.' + '.$y.' = ';
    } else {
        $key = $x.$my_salt.$mathkey.$y;
        $md5_name = md5($key).'.png'; // name of png image we want
        if(!file_exists($my_captcha_folder.$md5_name)) { // image doesn't already exist
            $my_img = imagecreate(80, 20); // let's create a new one using the day of the month, my salt and the $x & $y
            imagesavealpha($my_img, true); 
            $trans_color = imagecolorallocatealpha($my_img, 0, 0, 0, 127); 
            imagefill($my_img, 0, 0, $trans_color);
            $text_color = imagecolorallocate($my_img, 0, 0, 0);
            imagestring($my_img, 5, 10, 3, "$x + $y =",
            $text_color);
            imagesetthickness($my_img, 5);
            imagepng($my_img,$my_captcha_folder.$md5_name); // save the image to the captchas folder
        }
        $math .= '<img src="'._SITE.$my_captcha_folder.$md5_name.'" alt="" style="vertical-align:middle" />'; // serve the image
    }
    $math .= '
        <input type="text" name="calc" id="calc" style="vertical-align:middle" />
        </p>';
    return $math;
}

1) "guvenlikkodu" isimli bir klasör oluşturun ve bu klasöre yazma izni verin...

Tüm bu işlemleri doğru bir şekilde uyguladıktan sonra artık sNews sisteminiz spam yorumlara karşı daha güçlü korunur hale gelmiş olacak...

Hiç yorum yok:

Yorum Gönder