How do I get the user IP address in Symfony2 controller?

前端 未结 5 525
粉色の甜心
粉色の甜心 2020-12-02 22:06

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

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

5条回答
  •  盖世英雄少女心
    2020-12-02 22:34

    For Symfony 2.6+ use the following code (within your controller:

          $this->container->get('request_stack')->getCurrentRequest()->getClientIp();
    

提交回复
热议问题