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

后端 未结 10 519
粉色の甜心
粉色の甜心 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:22

    If you'd like to use a pre-built library, you can use Whip.

    Using pre-made libraries are usually better because most of them will have been checked thoroughly by an active community. Some of them, especially the ones that have been around for a long time, have more features built-in.

    But if you want to code it yourself to learn the concept, then it's ok I guess. I recommend packaging it as a stand alone library and releasing it as open-source :)

    EDIT: I do not recommend using the remote IP in security mechanisms as they are not always reliable.

提交回复
热议问题