HHawk Posted December 15, 2006 Share Posted December 15, 2006 Okay I have a simple domaincheck script on my website (actually 2 of them, but one is for quick checks only).Anyways, I don't want the website getting flooded by checks.So I want to add a flood control check; e.g. wait for 30 seconds before trying again (with a message in between saying wait for 30 seconds before trying again). Can someone tell me how to add it?Or if it's even possible (my first choice); I want it to limit to 5 quick checks on 1 IP adress a day. Of course also with a message like "You have already used the quick check 5 times today, please try again tomorrow".Since I can't do this myself, I am a real PHP newbie, I would be grateful with either option. :)Here is the code (single file):[code]<?php function checkDomain($domain,$server,$findText){ // Open a socket connection to the whois server $con = fsockopen($server, 43); if (!$con) return false; // Send the requested doman name fputs($con, $domain."\r\n"); // Read and store the server response $response = ' :'; while(!feof($con)) { $response .= fgets($con,128); } // Close the connection fclose($con); // Check the response stream whether the domain is available if (strpos($response, $findText)){ return true; } else { return false; } } function showDomainResult($domain,$server,$findText){ if (checkDomain($domain,$server,$findText)){ echo "<tr><td width=\"222\" align=\"left\">$domain</td><td width=\"50\" align=\"center\"><span class=\"dhvrij\">vrij</span></td></tr>"; } else echo "<tr><td width=\"222\">$domain</td><td width=\"50\" align=\"center\"><span class=\"dhbezet\">bezet</span></td></tr>"; }?><br><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="domain" id="domain"> <table width="272" border="0" cellspacing="0" cellpadding="0"> <tr><td align="center"><input class="text" name="domainname" type="text" size="36"></td></tr> <tr> <td align="center"> <input type="checkbox" name="alle" checked>Alle <input type="checkbox" name="nl">.nl <input type="checkbox" name="eu">.eu <input type="checkbox" name="com">.com <input type="checkbox" name="net">.net <input type="checkbox" name="org">.org </td></tr> <tr><td align="center" valign="middle"><br/><input class="text" type="submit" name="submitBtn" value="Controleer"></td> </tr> </table> </form><?php if (isset($_POST['submitBtn'])){ $domainbase = (isset($_POST['domainname'])) ? $_POST['domainname'] : ''; $d_all = (isset($_POST['alle'])) ? 'alle' : ''; $d_nl = (isset($_POST['nl'])) ? 'nl' : ''; $d_eu = (isset($_POST['eu'])) ? 'eu' : ''; $d_com = (isset($_POST['com'])) ? 'com' : ''; $d_net = (isset($_POST['net'])) ? 'net' : ''; $d_org = (isset($_POST['org'])) ? 'org' : ''; // Check domains only if the base name is big enough if (strlen($domainbase)>2){?><hr><table width="272px"><?php if (($d_nl != '') || ($d_all != '') ) showDomainResult($domainbase.".nl",'whois.domain-registry.nl','is free'); if (($d_eu != '') || ($d_all != '') ) showDomainResult($domainbase.".eu",'whois.eu','FREE'); if (($d_com != '') || ($d_all != '') ) showDomainResult($domainbase.".com",'whois.crsnic.net','No match for'); if (($d_net != '') || ($d_all != '') ) showDomainResult($domainbase.".net",'whois.crsnic.net','No match for'); if (($d_org != '') || ($d_all != '') ) showDomainResult($domainbase.".org",'whois.publicinterestregistry.net','NOT FOUND');?> </table><?php } }?> [/code]Like I said, this is just a quick and dirty check for lazy people. The other domaincheck is better. Link to comment https://forums.phpfreaks.com/topic/30797-how-to-add-flood-control/ Share on other sites More sharing options...
fert Posted December 15, 2006 Share Posted December 15, 2006 you could use sessions to store the last time they tried to check a domain name and compare it to the current time Link to comment https://forums.phpfreaks.com/topic/30797-how-to-add-flood-control/#findComment-142004 Share on other sites More sharing options...
HHawk Posted December 15, 2006 Author Share Posted December 15, 2006 Uhm... How do I pull that of?Remember I am PHP newbie. :S Link to comment https://forums.phpfreaks.com/topic/30797-how-to-add-flood-control/#findComment-142008 Share on other sites More sharing options...
fert Posted December 15, 2006 Share Posted December 15, 2006 put this at the very top of your script:[code]session_start();[/code]put this in before <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="domain" id="domain">[code]<?phpif($_SESSION['time']!="" || time()<($_SESSION['time']+30)){die("Flood control");}?>[/code]put this after if (isset($_POST['submitBtn'])){[code]$_SESSION['time']=time();[/code] Link to comment https://forums.phpfreaks.com/topic/30797-how-to-add-flood-control/#findComment-142020 Share on other sites More sharing options...
HHawk Posted December 15, 2006 Author Share Posted December 15, 2006 Thanks I will give that a go!I hope it works. :)/editWell it seems it doesn't do a thing... I still can press the search buttons over and over. :SWhat's wrong? Link to comment https://forums.phpfreaks.com/topic/30797-how-to-add-flood-control/#findComment-142028 Share on other sites More sharing options...
HHawk Posted December 16, 2006 Author Share Posted December 16, 2006 Anyone? Link to comment https://forums.phpfreaks.com/topic/30797-how-to-add-flood-control/#findComment-142318 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.