[英]How to detect local ip address
this is my code to detect my system ip Address 这是我的代码来检测我的系统IP地址
<?php
if ($_POST['login']) {
$uname = $_POST['uname'];
$pass = $_POST['pass'];
$email = $_POST['email'];
$phnoe = $_POST['phnoe'];
$ipd = $_SERVER['REMOTE_ADDR'];
if (mysql_query("Insert Into nennetwork (name, email, password, phone, useripp ) Values ('$uname', '$email', '$pass', '$phnoe', '$ipd' )"))
$pdmsg = "New Member Added!!";
}
and my IP is 192.168.7.16 but it is giving server address like 103.18.164.206.. i want my System's Ip Is it possible??? 和我的IP是192.168.7.16,但它给服务器地址,如103.18.164.206 ..我希望我的系统的IP有可能吗?
use $_SERVER['SERVER_ADDR'];
使用
$_SERVER['SERVER_ADDR'];
$_SERVER
is an array containing information such as headers, paths, and script locations.$_SERVER
是一个包含标题,路径和脚本位置等信息的数组。 The entries in this array are created by the web server.该数组中的条目由Web服务器创建。 There is no guarantee that every web server will provide any of these;
不能保证每个Web服务器都可以提供其中的任何一个。 servers may omit some, or provide others not listed here.
服务器可能会省略某些服务器,或提供此处未列出的其他服务器。 That said, a large number of these variables are accounted for in the » CGI/1.1 specification, so you should be able to expect those.
就是说,在»CGI / 1.1规范中考虑了很多这些变量,因此您应该可以期待这些变量。
Extra Knowledge 额外知识
$_SERVER['HTTP_HOST']
- gives http://192.168.0.1/index.php
$_SERVER['HTTP_HOST']
-提供http://192.168.0.1/index.php
$_SERVER['SERVER_NAME']
- gives www.example.com
$_SERVER['SERVER_NAME']
-提供www.example.com
$_SERVER['SERVER_ADDR']
- gives 127.0.0.1
$_SERVER['SERVER_ADDR']
-给出127.0.0.1
$_SERVER['REMOTE_ADDR']
- also gives 127.0.0.1
$_SERVER['REMOTE_ADDR']
-还给出了127.0.0.1
EDIT 01 编辑01
$ipAddress = $_SERVER['REMOTE_ADDR'];
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
$ipAddress = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));
}
As it seems your page is hosted on an internet network (for example ip of the server is 2.178.xx
). 看起来您的页面托管在Internet网络上(例如,服务器的ip为
2.178.xx
)。 In this case what I can say is that you cant . 在这种情况下,我只能说你做不到 。
Web Servers can not access inside of the user's network. Web服务器无法访问用户网络内部。 for example, you have a wifi modem and 3 people are connected.
例如,您有一个wifi调制解调器,并且连接了3个人。 the webserver can only sees your outer (internet) ip address not the inner (in wifi network, sth like
192.168.xx
) 网络服务器只能看到您的外部(互联网)IP地址,而看不到内部(在wifi网络中,例如
192.168.xx
)
So the answer is: you cant. 所以答案是:你不能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.