Username: Posted September 24, 2010 Share Posted September 24, 2010 I wrote a script that inserts an IP to a text file called 'banlist.txt', it works. But how can I read the text-file, and for everyline of IPs, die and don't let them see the content? I've got this so far <?php $file = @fopen("banlist.txt", "r"); if ($file) { while (!feof($file)) { $buff = fgets($file, 4096); echo "" . $buff . "<br />"; } fclose($handle); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/214329-read-banlisttxt-and-ban/ Share on other sites More sharing options...
trq Posted September 24, 2010 Share Posted September 24, 2010 Something like.... <?php if ($lines = file('banlist.txt')) { foreach ($lines as $line) { if ($line == $_SERVER['REMOTE_ADDR']) { die(); } } } Quote Link to comment https://forums.phpfreaks.com/topic/214329-read-banlisttxt-and-ban/#findComment-1115338 Share on other sites More sharing options...
Rifts Posted September 24, 2010 Share Posted September 24, 2010 two things. first you should be able to read the txt file and put the IPs in an array and then in your code do something like $ip=$_SERVER['REMOTE_ADDR']; then run $ip against your arry and if there is a match redirect them to yourwebsite.com/yousuck or something and second it would still be easy to access your website if you were ban by using a proxy Quote Link to comment https://forums.phpfreaks.com/topic/214329-read-banlisttxt-and-ban/#findComment-1115339 Share on other sites More sharing options...
Username: Posted September 24, 2010 Author Share Posted September 24, 2010 two things. first you should be able to read the txt file and put the IPs in an array and then in your code do something like $ip=$_SERVER['REMOTE_ADDR']; then run $ip against your arry and if there is a match redirect them to yourwebsite.com/yousuck or something and second it would still be easy to access your website if you were ban by using a proxy >proxy What's your point? Lol. Quote Link to comment https://forums.phpfreaks.com/topic/214329-read-banlisttxt-and-ban/#findComment-1115340 Share on other sites More sharing options...
trq Posted September 25, 2010 Share Posted September 25, 2010 By using a proxie a user can change the ip the access your site via. Most users will have a dynamic ip address anyway, these can change anywhere from weekly to hourly. Not much you can do about it. Quote Link to comment https://forums.phpfreaks.com/topic/214329-read-banlisttxt-and-ban/#findComment-1115342 Share on other sites More sharing options...
Username: Posted September 25, 2010 Author Share Posted September 25, 2010 By using a proxie a user can change the ip the access your site via. Most users will have a dynamic ip address anyway, these can change anywhere from weekly to hourly. Not much you can do about it. Lol I know what a proxy does. From my experience with networking a majority of people have static. Quote Link to comment https://forums.phpfreaks.com/topic/214329-read-banlisttxt-and-ban/#findComment-1115343 Share on other sites More sharing options...
Username: Posted September 25, 2010 Author Share Posted September 25, 2010 Something like.... <?php if ($lines = file('banlist.txt')) { foreach ($lines as $line) { if ($line == $_SERVER['REMOTE_ADDR']) { die(); } } } I'm confused with what to do Quote Link to comment https://forums.phpfreaks.com/topic/214329-read-banlisttxt-and-ban/#findComment-1115344 Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2010 Share Posted September 25, 2010 After you use file(), you could use in_array() to find if there is a match. Quote Link to comment https://forums.phpfreaks.com/topic/214329-read-banlisttxt-and-ban/#findComment-1115345 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.