AviNahum Posted September 19, 2009 Share Posted September 19, 2009 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.