Jump to content

avoid spaming code


AviNahum

Recommended Posts

I'm trying to build code that avoid spam comments on my site.

I made a function that checks the last time the user commented, and if passed more than 30 seconds it allows them to comment again.

i dont know why, but it's not work for me.

 

this is the function:

<?php
public function check_spam()
{
	global $core, $DB;

	//----------------------------------
	// Select from DB the last reply
	//----------------------------------

	$q4 = $DB->query("SELECT * FROM blog_articles_replies WHERE poster_ip='{$core->input['IP_ADDRESS']}' ORDER BY id DESC LIMIT 1");				
	$row = $DB->fetch_array($q4);

	//----------------------------------
	// Format the time to seconds
	//----------------------------------

	$last_post_date = $core->get_date($row['date'], "s");
	$now_date = $core->get_date(time(), "s");

	//----------------------------------
	// Check if 30 seconds past
	//----------------------------------

	if ( ($last_post_date+30) > $now_date )
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}
?>

 

$core->input['IP_ADDREDD'] is the user IP ADDRESS;

 

$core->get_date function:

<?php
public function get_date($date, $method="")
{
    		global $core;
    	
	//----------------------------------
	// Set an method if we didnt yet
	//----------------------------------

    		if ($method == "")
    		{
    			$method = "j/m/Y - G:i";
    		}
    	
    		//----------------------------------
	// Returning
	//----------------------------------

	return gmdate($method, $date);
}
?>

 

when i select 'DATE' from the DB, it's the miliseconds using time() function

 

I tried to explain myself and my problem the best I can

 

Thanks!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.