How to use HTTP_X_FORWARDED_FOR properly?

前端 未结 6 1600
既然无缘
既然无缘 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 17:37

    I like Hrishikesh's answer, to which I only have this to add...because we saw a comma-delimited string coming across when multiple proxies along the way were used, we found it necessary to add an explode and grab the final value, like this:

    $IParray=array_values(array_filter(explode(',',$_SERVER['HTTP_X_FORWARDED_FOR'])));
    return end($IParray);
    

    the array_filter is in there to remove empty entries.

提交回复
热议问题