我正在尝试实现一个供我自己使用的小应用程序,它可以读取从联系表单发送到我的数据库的数据,并且我希望能够禁止不受联系表单内容欢迎的用户,等等。所以我,我有每个用户的 IP,它是随表格发送的。但是,每次我点击禁止按钮时,它只会将拒绝保存到数据库,我想知道为什么。这是整个代码:
<?php
if(isset($_POST['submit'])) {
// Read the while file into a string $htaccess
$htaccess = file_get_contents('.htaccess');
// Stick the new IP just before the closing </files>
$new_htaccess = str_replace('allow from all', "deny from "."$unwanteduser"."\nallow from all", $htaccess);
// And write the new string back to the file
file_put_contents('.htaccess', $new_htaccess);
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Yhteydenottopyynnöt</title>
<style>
body{width:100%;}
tr:nth-child(even) { background: #ccc; }
</style>
</head>
<body>
<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db", $con);
$result = mysql_query("SELECT * FROM wp_contactform");
$f = fopen(".htaccess", "a+");
$ip = $row['IP'];
fwrite($ip , $f);
fclose($f);
echo "<table border='1'>
<tr>
<th style='width:5%;'>ID</th>
<th style='width:10%;'>Nimi</th>
<th style='width:10%;'>Puhelin</th>
<th style='width:10%;'>Sposti</th>
<th style='width:40%;'>Viesti</th>
<th style='width:10%;'>Päivä</th>
<th style='10%;'>IP</th>
<th style='5%;'>Ban</th>
</tr>";
$i = 0;
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td style='width:10%;'>" . $row['ID'] . "</td>";
echo "<td style='width:10%;'>" . $row['Nimi'] . "</td>";
echo "<td style='width:10%;'>" . $row['Puhelin'] . "</td>";
echo "<td style='width:10%;'><a href='mailto:" . $row['Email'] . "'>" . $row['Email'] . "</a></td>";
echo "<td style='width:40%;'>" . $row['Viesti'] . "</td>";
echo "<td style='width:10%;' >" . $row['Day'] . "</td>";
echo "<td style='width:10%;'>" . $row['IP'] . "</td>";
$unwanteduser = $row['IP'];
echo "<form action='thissamepage' method='post'><input type='hidden' value='$unwanteduser' name='gtfo'><input type='submit' name='submit' value='Ban'>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</body>
</html>