|
Posted by J.O. Aho on 09/18/05 22:06
Andy wrote:
> Bellow is a script to ban spammers addresses who are using feedback form to
> send spam. I am looking for a script , so I can get all senders IP
> addresses. Your help will be appreciated.
Just use a file where you can save the ip's that is posting, a bad but simple
way could be
exec("echo $HTTP_SERVER_VARS['REMOTE_ADDR'] >> /path/to/your/file.txt" );
> And this is my script:
>
> If you would like to ban certain IP addresses from submitting your form,
> change "no" to "yes" below.
> $ban_ip_on = "no";
why not just use true and false? IMHO it makes things a lot easier and faster
$ban_ip_on = false;
> IP addresses you would like to ban, seperated only by commas.
> $ban_ip_list = "111.222.33.55,11.33.777.99";
easier in my opinion to use an array and use the in_array function, this way
you get a well working if statement and _don't_ have the problem that you will
get a "true" for 111.222.33.5 which isn't listed in your list.
$ban_ip_list=array(
"111.222.33.55",
"11.33.777.99"
);
> Check If IP Address Is Banned.
> if($ban_ip_on == "yes") {
>
> if(strstr($ban_ip_list, $HTTP_SERVER_VARS[REMOTE_ADDR])) {
> echo "<h2> Error - Banned IP</h2>
> You cannot use this form because your IP address has been banned by the
> administrator.<br>";
> $error = "yes";
> }
> }
>
>
> if($error == "yes") {
> exit();
> }
Why have extra if-statment?
if($ban_ip_on & in_array($HTTP_SERVER_VARS['REMOTE_ADDR'],
$ban_ip_list)) {
echo "<h2> Error - Banned IP</h2>
You cannot use this form because your IP address has been banned by
the administrator.<br>";
exit();
}
//Aho
Navigation:
[Reply to this message]
|