如何在 Symfony2 控制器中获取用户 IP 地址? [英] How do I get the user IP address in Symfony2 controller?

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

问题描述

我需要在提交表单后将评论用户的IP地址存储在数据库中.

I need to store the IP address of the users who comment, in the database after form submission.

有没有symfony2函数来获取IP?或者有什么其他方式获取IP?

Is there any symfony2 function to get the IP? Or any other way to get the IP?

推荐答案

可以使用Request服务获取客户端IP:

You can get the client IP using Request service:

$container->get('request')->getClientIp();

这篇关于如何在 Symfony2 控制器中获取用户 IP 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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