Help me with an AntiFlood

Hello! First of all, sorry for my english. I’m new here and I need some help from you guys :slight_smile:

I downloaded a free PHP shoutbox from the internet for my website and I customized it by adding some features. But there is one that I can’t get working because I’m not experienced at all, an AntiFlood system.

I know the method in english but I need someone to translate it in PHP language for me, please.

It looks like this:

  1. Get the last date the user posted a message.

  2. Compare this date to the actual date and if the difference is bigger than 60 seconds: post the message

if not, inform the user that he can post only 1 message a minute.

Can somebody do this for me?

I think that’s the function to send messages:
[php]private function addShout($nickname = null, $ville = null, $gsm = null, $message = null)
{
$time = date(‘Y-m-d H:i:s’);
$query = mysql_query(“INSERT INTO shouts (nickname, ville, gsm, message, date_added) VALUES (’”.$nickname."’, ‘".$ville."’, ‘".$gsm."’, ‘".$message."’,’".$time."’);");

if(!$query) {
    $this->returnShouts(null, 'Database connection problem!');      
} else {
    $this->returnShouts('Shout added successfully');
}[/php]

If somebody has got a new ideea, let me know :slight_smile:

Hi there,

This is untested, but see if this does what you want:
[php]
$time = date(‘Y-m-d H:i:s’);
$query = mysql_query(“SELECT date_added FROM shouts WHERE nickname = '”.$nickname."’ ORDER BY date_added DESC LIMIT 1");
$res = mysql_fetch_assoc($query);
$prevtime = strtotime($res[‘date_added’]);
if(time() - $prevtime >= 60)
{
do it;
}
[/php]

Let me know if this works out for you.

Hey! Thank you for your reply,

It means that my function will look like this:
[php]private function addShout($nickname = null, $ville = null, $gsm = null, $message = null)
{
$time = date(‘Y-m-d H:i:s’);
$query = mysql_query(“SELECT date_added FROM shouts WHERE nickname = '”.$nickname."’ ORDER BY date_added DESC LIMIT 1");
$res = mysql_fetch_assoc($query);
$prevtime = strtotime($res[‘date_added’]);
if(time() - $prevtime >= 60)
{
do it;
}[/php]

Right?

It says “An error occured” and nothing more.

Didn’t you forget the [php] if(!$query) {
$this->returnShouts(null, ‘Database connection problem!’);
} else {
$this->returnShouts(‘Shout added successfully’);
}[/php] thing ?

I can send you my shoutbox to analyse it if you want to, Smokey. Thank you for your help :slight_smile:

Is that a PHP error or MySQL error do you know?

I thinks it’s a PHP error but I’m not sure .

Sponsor our Newsletter | Privacy Policy | Terms of Service