Page 1 of 1

feedback form keywords blacklist

Posted: Tue Jun 26, 2018 10:06 am
by marchello
Hi all,

I'd like to have keywords black list for my feedback form. Right now it works fine with just one keyword1 (see below). What to do with more keyword2, keyword3 and also in upper case? As I have almost no php experience, I would do it using several if-then-else blocks, though someone might kindly suggest me more elegant solution.
Please advise.
Thanks ahead.

Code: Select all

<?php

function getUserIP()
{
    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];

    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }

    return $ip;
}

        $user_ip = getUserIP();
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        $ref = @$_SERVER[HTTP_REFERER];
        $nl = nl2br("   |||||   ");
        $email_domain = substr($_REQUEST['email'], 0, strrpos($_REQUEST['email'], '@'));

        $headerFields = array(
            "MIME-Version: 1.0",
            "Content-Type: text/html;charset=utf-8"
        );

        if (!filter_var($_REQUEST['email'], FILTER_VALIDATE_EMAIL)) {
            $desc = $desc.'Email is not valid.';
            $host  = $_SERVER['HTTP_HOST'];
            $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
            $extra = 'error.php';
            header("HTTP/1.1 409 CONFLICT");
            header("Location: http://$host$uri/$extra");
        } else
        if (strpos($_REQUEST['message'], 'keyword1') !== false) {
            $desc = $desc.'Forbidden content.';
            $host  = $_SERVER['HTTP_HOST'];
            $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
            $extra = 'error3.php';
            header("HTTP/1.1 409 CONFLICT");
            header("Location: http://$host$uri/$extra");
        } else ... 

Re: feedback form keywords blacklist

Posted: Tue Jun 26, 2018 1:47 pm
by hyper
Put your keywords in an array and use a built in array search function, I'm sure you can work out how to do a case insensitive search.