Forum Moderators: coopster

Message Too Old, No Replies

PHP Chat scripts

How to prevent spamming

         

StoutFiles

11:58 am on Jul 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The most common spam in some of my chats are that people post the same line over and over.

UserBob: hey
UserBob: hey
UserBob: hey
UserBob: hey
UserBob: hey
UserBob: hey
UserSandy: stop
UserBob: hey
UserBob: hey
UserBob: hey
UserBob: hey
UserBob: hey

Anyways, what I'd like to do is prevent a user from posting the same line over and over...at the very least prevent the very next post from being the same as the previous post. I'd like to be able to do this without checking the database first to see if the previous row is the same as the newest post; I feel there should be an easier way.

Any ideas?

barns101

12:06 pm on Jul 16, 2008 (gmt 0)

10+ Year Member



A bot probably wouldn't accept cookies so I'll rule that option out. How about adding a hidden form field containing the user's last post?

StoutFiles

12:26 pm on Jul 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wwll it's not a bot doing it, just annoying users. But I can't have a login for the chat; it would defeat the purpose of it.

Maybe store the post in a session variable? I'm not sure how that would correlate with other users though. Hmm...

With a hidden from field I'd still have to pull out the users last post which would be a database call...I want to avoid doing that because it would bog down the script even more in the long run(it's used a lot, I need to preserve CPU memory on php scripts).

WesleyC

4:55 pm on Jul 16, 2008 (gmt 0)

10+ Year Member



session_start(); //If the session is already started, omit this

if ($_SESSION['last_post'] == $_POST['message'])
{
//Deny message
}
else
{
//Accept message
}

$_SESSION['last_post'] = $_POST['message'];

jedz

7:07 pm on Jul 16, 2008 (gmt 0)

10+ Year Member



We need to do something about it. This shouldn't be ignored

PHP_Chimp

8:29 pm on Jul 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Although I would not usually suggest a javascript option, have you thought about moving the processing to the users machine?

I would have thought that most people who are likely to be doing that sort of spam are not likely to be intelligent enough to just turn off javascript.

There will be some that get through, but try it and see. As if your cpu is taking a bit of a hammering this is a solution that doesnt eat any more of your resources.

Sessions would be great, however they will eat up more resources.

[edited by: PHP_Chimp at 8:30 pm (utc) on July 16, 2008]

StoutFiles

1:43 am on Jul 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I found a freeware Java chat for now, my server just can't take the pounding of a PHP/MYSQL chat and I'd rather not switch to a dedicated server until I build up a bankroll first. In due time though.

I did use some sessions, haha no wonder it crashed it the next day.