doudun1934 2017-01-18 16:08
浏览 76
已采纳

我使用filter_input的方式有什么问题? [重复]

I am told that I should use filter_input rather than accessing $_SERVER directly

So I made this simple 2 line of code

    echo "filter:input " . filter_input(INPUT_SERVER,'REMOTE_ADDR');
    echo "SERVER:" .$_SERVER['REMOTE_ADDR'] ; 

Very simple. I expect they both produce the exact same thing.

This is what I got

filter:input SERVER:202.80.212.17

Clearly filter_input(INPUT_SERVER,'REMOTE_ADDR') produces empty string.

Why?

</div>
  • 写回答

1条回答 默认 最新

  • doujue9767 2017-01-18 16:17
    关注

    It has been a bug in older versions of php. You can either use

    echo "filter:input " . filter_input(INPUT_ENV, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
    

    Or use

    echo "filter:input " . filter_input($_SERVER['REMOTE_ADDR']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?