ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I'm making a simple php script to read a list of IPs from a file into an array, and ban - exit() - the user if the ip matches. When the IPs are manually typed in the script, it works, i.e.
$banned_ip = '126.96.36.199';
$banned_ip = '188.8.131.52';
But when i stick the addresses in a file, it doesn't seem like its doing the if check.. Here's my code
$banned_ip = file("banlist.txt");
$ip = $_SERVER['REMOTE_ADDR'];
// Ban if IP matches.
echo "You have been banned!";
where banlist.txt contains an ip address per line. If i add echo $banned_ip; or echo $ip; i get the values i want... so i guess the problem is with the if(in_array(......)
Originally posted by msound lets say:
and you're in /www/html/forum/template, the following should work:
$out = `grep $ip ../../banlist.txt';
Ignoring the typo ' , But i've already tried it. It just won't read banlist.txt at all. Even if its in the current directory or any other. All i get is 'success' even if i stick my ip address in the list, delete the list, rename it, whatever =/
is 192.168.0.69 equal to 192.168.0.69 ? yes!
You have been banned
I guess i could stick to this script, although i'm itching to know why the other one refused to work in certain cases.
edit: hmm, i'd also want to stick an exit(); code with the banned part.
Probably in the if condition, before the break; would be the best place
is 184.108.40.206 equal to 192.168.0.69 ? no
is 220.127.116.11 equal to 192.168.0.69 ? no
is 18.104.22.168 equal to 192.168.0.69 ? no
is 22.214.171.124 equal to 192.168.0.69 ? no
is 126.96.36.199 equal to 192.168.0.69 ? no
is 188.8.131.52 equal to 192.168.0.69 ? no
is 184.108.40.206 equal to 192.168.0.69 ? no
is 220.127.116.11 equal to 192.168.0.69 ? no
is equal to 192.168.0.69 ? no
I should have been more precise
I didn't mean to replace the test :
if(strcmp($ip, $buffer) == 0)
As you pointed out, the script originally tested the empty lines
so I thought that before the test :
if(strcmp($ip, $buffer) == 0)
We could add :
So the loop skips the empty lines