简体   繁体   中英

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 ?

Can I get both ipv4 and 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. ( or any function, any way to get both, ipv4 and ipv6 )

Edit2: that is how I get ip right now:

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

and it returns ipv6 exclusively. ( 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 )

If user connected with IPv6 then there is no IPv4 address to display and vice versa. You always get only one version of IP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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