HostGator
Use SMFHELP25OFF for 25% off!

Author Topic: [Tip/Trick]  How to block links in the subject line of posts!  (Read 6886 times)


0 Members and 1 Guest are viewing this topic.

July 13, 2017, 11:57:25 AM

Offline admin

  • Administrator
  • Jr. Member
  • *
  • Posts: 15
  • Karma: 0
    • View Profile
    • SMF Help
[Tip/Trick] How to block links in the subject line of posts!
« on: July 13, 2017, 11:57:25 AM »

(Register to disable this ad!)
Spammers deserve a special place in *. They register with random pseudo-names, post one or two spam messages and annoy everyone on the forum. One of the methods they use is to post links to their garbage websites in the subject of the post; that way, the link is prominently displayed in the list of posts.

Here's a simple trick to block links in the subject of a post:

First, open /Themes/default/languages/Errors.english.php and add this at the end (or anywhere):

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

Now open /Sources/Post.php

Find:
Code: [Select]
	// 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 this after:
Code: [Select]
    // HTTP not allowed!
    if (substr_count(strtolower($_POST['subject']),"http://") > 0 || substr_count(strtolower($_POST['subject']),"https://") > 0)
        {
       $post_errors[] = 'bad_subject';
        }

If you want to also block www. in the subject, use this instead of the above code:
Code: [Select]
// http not allowed!
    if (substr_count(strtolower($_POST['subject']),"http://") > 0 || substr_count(strtolower($_POST['subject']),"https://") > 0 || substr_count(strtolower($_POST['subject']),"www.") > 0)
        {
       $post_errors[] = 'bad_subject';
        }

Now, when they try to post a message with a URL in the subject they will be greeted with a nasty error message:




Feel free to change the error message text to whatever you want and add translations to other language files you use on your forum.   ;)
« Last Edit: July 13, 2017, 12:03:21 PM by admin »

Tags:
 

HostGator
Use SMFHELP25OFF for 25% off!