LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 687 users online 221778 members 1064 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
Forever Angel
Music: Country, classic rock
Mood: Carefree
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
5 online / 34 MPM
Fresh Topics
  LiveWire / Technical Forums / Web Design & Search Engine Optimization / Viewing Topic

PHP help
Replies: 3Last Post Mar. 28 4:14pm by BoXLunch
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( yoshiness )


Enlightened One

Patron
Reply
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.

-------
"Last night I tried to slip it in her rear. When she began to
complain about the pain, I stupidly told her to take it like a man."

~Quantumleaper


11:34 pm on Dec. 30, 2008 | Joined: Dec. 2007 | Days Active: 504
Join to learn more about yoshiness Texas, United States | Straight Male | Posts: 7,902 | Points: 14,618
LiveWire Humor
revived5656


Connoisseur
Reply
google it

-------
"Cool Story bro, Can you write another?"
"I like to hit to from the back." (No Homo)

11:35 pm on Dec. 30, 2008 | Joined: July 2008 | Days Active: 117
Join to learn more about revived5656 Georgia, United States | Lesbian Male | Posts: 5,820 | Points: 7,412
jkjslkjind


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


11:36 pm on Dec. 30, 2008 | Joined: June 2008 | Days Active: 9
Join to learn more about jkjslkjind United States | Posts: 77 | Points: 169
BoXLunch


Professional

Patron
Reply
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.

Post edited at 4:16 pm on Mar. 28, 2009 by BoXLunch

-------
Kill one man, and your a muderer.
Kill a million, and your a king.
kill them all, and you god.
line for rent. 74 characters max.


4:14 pm on Mar. 28, 2009 | Joined: Mar. 2009 | Days Active: 49
Join to learn more about BoXLunch Montana, United States | Lesbian Male | Posts: 2,501 | Points: 2,713
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Web Design & Search Engine Optimization / Viewing Topic