在很我的时候我们需要得到用户的真实ip地址,例如,日志记录,地理定位,将用户信息,网站数据分析等,其实获取ip地址很简单$_server['remote_addr']就可以了。
-
- $ip = $_server['remote_addr'];
-
- echo "remote addr: " . $_server['remote_addr']."<br/>";
- echo "x forward: " . $_server['http_x_forwarded_for']."<br/>";
- echo "clien ip: " . $_server['http_client_ip']."<br/>";
-
- function getip() {
- $ip = $_server['remote_addr'];
- if (!emptyempty($_server['http_client_ip'])) {
- $ip = $_server['http_client_ip'];
- } elseif (!emptyempty($_server['http_x_forwarded_for'])) {
- $ip = $_server['http_x_forwarded_for'];
- }
- return $ip;
- }
- /*
如果是是加密的代理是无法获取真实ip地址的。 |