How to use HTTP_X_FORWARDED_FOR properly?

前端 未结 6 1601
既然无缘
既然无缘 2020-12-05 17:01

Alright, I have an small authentication issue. My web service allows to connect to my API over HTTP with a username and password, but this connection can also be restricted

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 18:01

    HTTP_CLIENT_IP is the most reliable way of getting the user's IP address. Next is HTTP_X_FORWARDED_FOR, followed by REMOTE_ADDR. Check all three, in that order, assuming that the first one that is set (isset($_SERVER['HTTP_CLIENT_IP']) returns true if that variable is set) is correct. You can independently check if the user is using a proxy using various methods. Check this out.

提交回复
热议问题