I have a live chat and i need to ban if the users chatted more than 5 times in a row
this is the sql:
function countMessages() {
global $tsUser;
$querys = db_exec(array(__FILE__, __LINE__), 'query', 'SELECT * FROM c_chat_messages where msg_user = "'.$tsUser->uid.'" ORDER BY msg_id ASC');
$counts = db_exec('num_rows', $querys);
if($counts > 5) { $this->banUser(); }
}
$tsUser->uid is the id of the user
i need to check if the user chatted for more than 5 times in a row so the php executes the $this->banUser(); function
you have to take timestamp
of each message sent by the user in your database table. And than you can fire a query checking if the user has sent more than 5 messages in last 15 seconds, by calculating the time different between the messages.
to get last five messages sent by that user,
SELECT * FROM c_chat_messages where msg_user = "'.$tsUser->uid.'" ORDER BY msg_id DESC limit 0,5
than get the difference between last and first record returned by above query
.
to get time difference in seconds you can use
SELECT TIME_TO_SEC(TIMEDIFF('2010-08-20 12:01:00', '2010-08-20 12:00:00')) diff;
you can call a ajax file every one or two seconds to check this.
Let me know if further clarification needed.