如何在 PHP 网络服务中获取客户端的 IP 地址? [英] How can I get the client's IP address in a PHP webservice?

查看:34
本文介绍了如何在 PHP 网络服务中获取客户端的 IP 地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个 PHP 网络服务.我想记录使用此 Web 服务的 WS 客户端的所有传入连接.如何获取客户端的IP地址?

$_SERVER['HTTP_CLIENT_IP']

的值似乎总是空的.

解决方案

这应该是你想要的:

$_SERVER['REMOTE_ADDR']

<块引用>

用户所在的IP地址查看当前页面.

http://php.net/manual/en/reserved.variables.server.php

I have developed a PHP webservice. I would like to log all incoming connections of the WS clients, which are consuming this web service. How can I obtain the client's IP address? The value of

$_SERVER['HTTP_CLIENT_IP']

seems to be always empty.

解决方案

This should be what you want:

$_SERVER['REMOTE_ADDR']

The IP address from which the user is viewing the current page.

http://php.net/manual/en/reserved.variables.server.php

这篇关于如何在 PHP 网络服务中获取客户端的 IP 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆