我有一个实时聊天,如果用户连续聊天超过5次,我需要禁止
这是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是用户的id
我需要检查用户是否连续聊天超过5次,以便php执行$this->banUser();函数
发布于 2015-03-07 14:47:27
您必须在数据库表中获取用户发送的每条消息的timestamp。然后,您可以通过计算消息之间的时间差异来触发查询,检查用户在过去15秒内发送的消息是否超过5条。
为了获得该用户发送的最后五条消息,
SELECT * FROM c_chat_messages where msg_user = "'.$tsUser->uid.'" ORDER BY msg_id DESC limit 0,5而不是得到last and first record returned by above query之间的差异。
要获得以秒为单位的时间差,您可以使用
SELECT TIME_TO_SEC(TIMEDIFF('2010-08-20 12:01:00', '2010-08-20 12:00:00')) diff;您可以每隔一到两秒钟调用一次ajax文件来检查这一点。
如果需要进一步澄清,请让我知道。
https://stackoverflow.com/questions/28911561
复制相似问题