How to prevent URL's in post subject?

Started by BSD2000, July 13, 2017, 08:18:12 AM

Previous topic - Next topic

BSD2000

My forum has been flooded with spammers lately and I installed a few anti-spam measures to slow them down, including preventing them from posting URL's in the body of the message, but they are getting around that by posting spam URL's in the subject line.

I've searched high and low and I can't find a mod that prevents 'http://' URL's from being entered in the subject line. Is there a small bit of code I could add in the post template that would show an error message if a URL is entered as the subject?

vbgamer45

Open sources/Post.php

Find

// You are not!
if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
fatal_error('Knave! Masquerader! Charlatan!', false);

Add after

if (substr_count($_POST['subject'],"http://") > 0 || substr_count($_POST['subject'],"https://") > 0)
{
fatal_error('You are not allowed to use that subject line', false);
}
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

BSD2000


vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

BSD2000

I made one small change - I added strtolower() to force the subject text to all lowercase, just in case they try to bypass it using uppercase letters:

if (substr_count(strtolower($_POST['subject']),"http://") > 0 || substr_count(strtolower($_POST['subject']),"https://") > 0)
{
fatal_error('You are not allowed to use that subject line', false);
}


Works even better now.  :)

BSD2000

Now that I think about it, you could add a new error message in the file /Themes/default/languages/Errors.english.php file, like this:

$txt['error_bad_subject'] = 'You are not allowed to use that subject line.';

Then change the code in /Sources/Post.php to:

    // HTTP not allowed!
    if (substr_count(strtolower($_POST['subject']),"http://") > 0 || substr_count(strtolower($_POST['subject']),"https://") > 0)
        {
       $post_errors[] = 'bad_subject';
        }


And it will produce an error message that stays focused on the post, but lets them know there's a problem with the subject text, like the attached photo.  :)

vbgamer45

Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Kindred

Or, even better... prevent them from reistering in the first place.

See the FAQ entry on how to prevent spammers
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

GerryM



Advertisement: