npsari Posted May 17, 2007 Share Posted May 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51912-stoping-spammers-posting-junk-using-ip-address/ Share on other sites More sharing options...
per1os Posted May 17, 2007 Share Posted May 17, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/51912-stoping-spammers-posting-junk-using-ip-address/#findComment-255926 Share on other sites More sharing options...
npsari Posted May 17, 2007 Author Share Posted May 17, 2007 Dont need to exhaust you, but can someone show me the technique Just the Time function (I can relate it to the rest) How can I write the if function which says: Time is less that 6 hours Quote Link to comment https://forums.phpfreaks.com/topic/51912-stoping-spammers-posting-junk-using-ip-address/#findComment-255934 Share on other sites More sharing options...
per1os Posted May 17, 2007 Share Posted May 17, 2007 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/51912-stoping-spammers-posting-junk-using-ip-address/#findComment-255942 Share on other sites More sharing options...
npsari Posted May 17, 2007 Author Share Posted May 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51912-stoping-spammers-posting-junk-using-ip-address/#findComment-255949 Share on other sites More sharing options...
per1os Posted May 18, 2007 Share Posted May 18, 2007 <?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!'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51912-stoping-spammers-posting-junk-using-ip-address/#findComment-256361 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.