1.

Solve : php ban users from text file??

Answer»

hello

using php without a database, how can i ban users whos i.p is listed in a text file?
i KNOW how to ban users, but how do i get the i.p from a text file instead of an array

or how could i set the array to use i.ps from a text file?I believe the function you want to use is fget and then parse the returned array and check to see if the current IP is banned. Check out www.phpbuilder.net
thanks , i already figured out some of it though can you explain why the following isnt working?

<?php
$userIp = $_SERVER['REMOTE_ADDR'];
$ips = file('/ban.txt');
$isBanned = false;

foreach($ips as $ip) {
$split = explode(',', $ip);

if($split[0] == $userIp)
$isBanned = true;
BREAK;
}
}

if(!$isBanned) {
echo "It seems you have been banned from viewing this website.";
echo "
";
echo "If you think you have been banned in error please CONTACT me.";
exit();
}
}
?>
For starters, you have two start brackets and four end brackets. Take care of those and see what happens.

Quote from: m3rcllessd3ath on January 28, 2008, 09:49:43 AM

thanks , i already figured out some of it though can you explain why the following isnt working?

<?php
$userIp = $_SERVER['REMOTE_ADDR'];
$ips = file('/ban.txt');
$isBanned = false;

foreach($ips as $ip) {
$split = explode(',', $ip);

if($split[0] == $userIp)
$isBanned = true;
break;
}
}

if(!$isBanned) {
echo "It seems you have been banned from viewing this website.";
echo "
";
echo "If you think you have been banned in error please contact me.";
exit();
}
}
?>

thats got it, thanks again manI.P. banning is generally a BAD idea because it is indiscriminate and also because it can easily be circumvented.

See http://kalsey.com/blog/2004/02/why_ip_banning_is_useless/Quote from: Rob Pomeroy on February 08, 2008, 01:51:30 AM
I.P. banning is generally a bad idea because it is indiscriminate and also because it can easily be circumvented.

See http://kalsey.com/blog/2004/02/why_ip_banning_is_useless/

i know its somewhat usless by for my purpose it will work fine (chat service) , i upgraded to proxy detection,
and since the chat will be moderated anyways, even if they have a dynamic ip address they can come back as often as they want and keep beeing rebanned , doesent matter to me.. eventually they will give up.


Discussion

No Comment Found