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
https://forums.phpfreaks.com/topic/174804-avoid-spaming-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.