LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 752 users online 224651 members 1432 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
Paparazzi
Interests: Writing Video Games Make Up Hair...
Mood: Lifeless
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
7 online / 26 MPM
Fresh Topics
  LiveWire / Technical Forums / Web Design & Search Engine Optimization / Adding Reply

Quoting Post
Topic PHP help
Membername   Not a member? Sign Up Free (takes 20 seconds)
Password   Forgotten your password?
Post

Font:   Size:   Color:

FAQ Keyword Search:
Post Options
Favorites Manager
Notify me of new replies to this topic by email
Notify me of new replies to this topic by private message
Original Post
yoshiness Posted at 11:34 pm on Dec. 30, 2008
How exactly do you get PHP to read from a certain file?

I'm trying to create a "banned" list, and if their IP appears in the list, they won't be allowed.

I'm basically setting up futallaby because I fail at setting up serissa and Wakaba on a free server.^^;

Code:
$badip = array("addr1\\.dummy\\.com","addr2\\.dummy\\.com"); //Refused hosts (IP bans)

That's the function that appears in the imgboard.php file
What do I need to change it to get it to read from a .txt or database file or whatever. Please go into detail about the database, as I'd like that a little better, but the .txt file is also good.

Replies
BoXLunch Posted at 4:14 pm on Mar. 28, 2009
Quote: from jkjslkjind at 11:36 pm on Dec. 30, 2008

$handle = fopen('filename.txt','r');  
$thisisthelist = fread($handle,9000);  
fclose($handle);  
$badip = explode($thisisthelist,"\n");  


I would like to expand on this.

Code:
$handle = fopen('filename.txt','r');
$thisisthelist = fread($handle,9000);
fclose($handle);
$badip = explode($thisisthelist,"\n");

Could probably go as

$handle = fopen('filename.txt','r');
$thisisthelist = fread($handle, filesize('filename.txt'));
fclose($handle);
$badip = explode($thisisthelist,"\n");
$banned = false;
while (list ($key, $val) = each ($badip)) {
if($val == $_SERVER['REMOTE_ADDR']) {
$banned = true;
}
}
if($banned) {
#do bad stuff
}

This actualy cycles trough the list, checks to see if the ip is there.

jkjslkjind Posted at 11:36 pm on Dec. 30, 2008
$handle = fopen('filename.txt','r');
$thisisthelist = fread($handle,9000);
fclose($handle);
$badip = explode($thisisthelist,"\n");

revived5656 Posted at 11:35 pm on Dec. 30, 2008
google it
All 3 previous replies displayed.