简体   繁体   English

在Symfony2中获取客户端IP

[英]Get Client Ip in Symfony2

I have searched, but cannot seem to find an answer to this simple question: 我已经搜索过,但似乎找不到这个简单问题的答案:

How do I force symfony to give me the ipv4 version of user's ip, or am I missing something ? 如何强制symfony为我提供用户ip的ipv4版本,或者我缺少什么?

Can I get both ipv4 and ipv6 ? 我可以同时获得ipv4和ipv6吗?

Thanks 谢谢

Edit: My question is different, because I am not trying to get any ip, I know of the function getClientIP ( that's why it is in the title ), I want the function to return an ipv4 and ipv6 version of ip. 编辑:我的问题是不同的,因为我没有尝试获取任何ip,我知道函数getClientIP(这就是为什么它在标题中),我希望该函数返回ipv4和ipv6版本。 ( or any function, any way to get both, ipv4 and ipv6 ) (或任何功能,以任何方式同时获得ipv4和ipv6)

Edit2: that is how I get ip right now: Edit2:那就是我现在得到IP的方式:

public function getUserIp()
{
    return $this->request->getClientIp();
}

and it returns ipv6 exclusively. 并专门返回ipv6。 ( this function is ran from inside of my own UserManager, that checks and updates the current user on every call, by plugging an event to the controller enter part symfony pipeline ) (此功能是在我自己的UserManager中运行的,该功能通过将事件插入控制器的输入symfony管道,在每次调用时检查并更新当前用户)

If user connected with IPv6 then there is no IPv4 address to display and vice versa. 如果用户连接了IPv6,则没有要显示的IPv4地址,反之亦然。 You always get only one version of IP. 您始终只能获得一个IP版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM