【问题标题】:How my ip address will come automatically in a texbox [duplicate]我的IP地址如何自动出现在文本框中[重复]
【发布时间】:2014-09-07 19:50:28
【问题描述】:

我在页面调用查询中有一个文本框。

我希望当我的页面加载时我的 ip 地址会自动出现在那个 texbox 中...请帮助我..我需要您尽快提出建议。

【问题讨论】:

标签: html


【解决方案1】:

您使用什么语言(服务器端)?

如果您想在 PHP 中执行此操作,方法如下:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
?>


<form>
<!-- other form elements here -->
<input type="text" name="ip" value="<?php if isset($ip) { echo $ip; } ?>" />
</form>

第一部分获取用户的 IP 地址。第二部分在文本字段中打印其值。

【讨论】:

    【解决方案2】:

    您希望您的用户在文本框中看到他们的 IP 地址吗?

    假设您必须在客户端执行此操作,则需要使用 javacript。像这样(取自How to get client's IP address using javascript only?):

    <script type="application/javascript">
        function getip(json){
          alert(json.ip); // alerts the ip address
          // instead of the alert, assign the value to your text box
        }
    </script>
    
    <script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-28
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      • 2011-05-07
      相关资源
      最近更新 更多