我想獲得發佈評論/反饋的人的IP並將其保存在數據庫中。下面是代碼:當有人發佈反饋時獲取IP
<form action="feedback.php" method="POST">
<table width="450px">
</tr>
<tr>
<td valign="top">
<label for="name">Name *</label>
</td>
<td valign="top">
<input type="text" name="name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comment">Message *</label>
</td>
<td valign="top">
<textarea name="comment" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" name="add" value="Add FeedBack">
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['add'])){
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
if($name){
if($email){
if($comment){
mysql_query("INSERT INTO comments (id, name, email, comment) VALUES ('','$name','$email','$comment')");
}
else
echo "You haven't entered any comment!";
}
else
echo "You haven't entered an email address!";
}
else
echo "You haven't entered your name!";
}
?>
<?php
$run = mysql_query("SELECT * FROM comments ORDER BY id DESC");
$numrows = mysql_num_rows($run);
if($numrows > 0){
while($row = mysql_fetch_assoc($run)){
$dbname = $row['name'];
$dbcomment = $row['comment'];
echo "Commented By $dbname<br>$dbcomment<br><br>";
}
}
else
echo "<br>There are no feedbacks made";
?>
能有人告訴我我該怎麼使用,如何使它獲得IP? (我知道如何讓它存儲在數據庫中,但我不知道如何讓它獲得評論者的IP)。
很好的答案在這裏http://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php – DevDonkey 2014-12-13 14:48:35