PHP most accurate / safe way to get real user IP address in 2017

后端 未结 10 516
粉色の甜心
粉色の甜心 2021-01-01 15:51

What is the most accurate way to get user\'s IP address in 2017 via PHP?

I\'ve read a lot of SO questions and answers about it, but most of answers are old and comme

10条回答
  •  攒了一身酷
    2021-01-01 16:14

    Short answer:

    $ip = $_SERVER['REMOTE_ADDR'];


    As of 2019 $_SERVER['REMOTE_ADDR']; is the only reliable way to get users ip address, but it can show erroneous results if behind a proxy server.
    All other solutions imply security risks or can be easily faked.

提交回复
热议问题