Jump to content

Stoping spammers posting junk using IP address!!!


npsari

Recommended Posts

hi guys

 

I am back with a new interesting question

 

I have a colomb which stores the users IP

 

I use this code to insert data

 

<?php 
mysql_select_db("databse", $con); 

$IP=GetHostByName($REMOTE_ADDR); 
$Date = date("Y/m/d");

$tim = localtime(time(),true);
$Time=($tim['tm_hour'].":".$tim['tm_min'].":".$tim['tm_sec']);

$query="INSERT INTO ads (Email, Title, Date, Time, IP) VALUES ('$Email', '$Title', '$Date', '$Time', '$IP')"; 

print "Data was inserted successfully"; 
?> 

 

How can I stop the same IP adding to databse unless minium 6 hours pass by

 

what should i add

You should probably add a timeentered column so you have a date to reference and than before you insert another ad pull out all ads from a certain ip and than do a date/timecheck with the timeentered in the db and if the timeentered is less than 6 hours do not allow it to be inserted.

<?php

$timeAgainst = strtotime($dbTime);
$timeNow = time()-3600*6; // time now minus 6 hours ago

if ($timeAgainst > $timeNow) {
     echo 'Sorry you recently entered an ad, please wait at least 6 hours from time of entry.';
}else {
     echo 'Data has been inserted!';
}
?>

 

I always screw up on date logic, do some tests and see if that jives. if not try flipping the > to < and see what happens.

Can we do it differently

 

How can I say...

 

Time (when IP was submitted which i will derive) - Time now = Less than 6 hours

print "Sorry";

 

Show me function please, with these variables:

Time now is $Timenow

Time submitted is $Time

<?php

$timeAgainst = strtotime($dbTime);
$timeNow = time(); // time now minus 6 hours ago

if (($timeAgainst - $timeNow) < time()-3600*6) {
     echo 'Sorry you recently entered an ad, please wait at least 6 hours from time of entry.';
}else {
     echo 'Data has been inserted!';
}
?>

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.