|
-- Posted by yoshiness 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.
-- Posted by revived5656 at 11:35 pm on Dec. 30, 2008
google it
-- Posted by jkjslkjind at 11:36 pm on Dec. 30, 2008
$handle = fopen('filename.txt','r'); $thisisthelist = fread($handle,9000); fclose($handle); $badip = explode($thisisthelist,"\n");
-- Posted by BoXLunch 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.
|