drf65218 2014-12-13 14:45
浏览 18
已采纳

有人发布反馈时获取IP [重复]

This question already has an answer here:

I want to get the IP of someone that posts a comment/feedback and save it in the database. Here is the code:

<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";
?>


Can someone please tell me what can I use and how to make it get the IP? (I know how to make it store in the database, but I don't know how to make it get the IP of the commenter).

</div>
  • 写回答

2条回答 默认 最新

  • 普通网友 2014-12-13 14:48
    关注

    You can get the users IP with $_SERVER['REMOTE_ADDR'] in php

    For additional information, I refer to the answer here, also recommended by @Matt Holbrook-Bull

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?