【发布时间】:2014-09-07 19:50:28
【问题描述】:
我在页面调用查询中有一个文本框。
我希望当我的页面加载时我的 ip 地址会自动出现在那个 texbox 中...请帮助我..我需要您尽快提出建议。
【问题讨论】:
-
你需要服务器端脚本,所以你用的是哪个?
-
在发布问题之前先谷歌
标签: html
我在页面调用查询中有一个文本框。
我希望当我的页面加载时我的 ip 地址会自动出现在那个 texbox 中...请帮助我..我需要您尽快提出建议。
【问题讨论】:
标签: html
您使用什么语言(服务器端)?
如果您想在 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 地址。第二部分在文本字段中打印其值。
【讨论】:
您希望您的用户在文本框中看到他们的 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>
【讨论】: