I am a PHP newbie, and I have written a script, but I am not sure why it does not work.
The script is supposed to open ‘banip.txt’ where there is a list of banned IP addresses (1 per line). You then change what is in the text area (e.g. add an IP) and then you click Save, then it saves the text file.
This does not work, what seems to happen is the file does got get modified when you post the form.
Could someone please correct my code? This is for running on PHP5 in Windows.
[code=php]
<?
/*
require(“config.php”);
require(“functions.php”);
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
$auth = auth();
if ($auth != 2) { die(‘Access denied’); }
*/
if($ips != “” ) {
echo $ips; //for debug
fwrite(‘banip.txt’,$ips);
fclose(‘banip.txt’);
}
?>
<form action=”<? $_SERVER[‘PHP_SELF’] ?>” method=”post”><?
$ips = file(‘banip.txt’);
echo”<textarea name=”ips”>”;
$ips = implode(“”, $ips);
echo $ips;
echo”</textarea>”;
fclose($ips);
?><input type=”submit” value=”Save”>
</form>