dongmu1951 2010-03-24 06:13
浏览 46
已采纳

如何在PHP中检查访问者IP地址的代码功能?

I still confused on this subject and ask for any help and reference on how to check a visitor IP address via PHP.

I'm know it seems lazy to ask something before attempting to code something to show, but right now, I am also googling to find it. Hopefully someone can give general broad answer or some link to read?

BTW, what is to be considered when we have to code some feature like this?

PS: Thank you very much everybody. It's been enlightening arguments. Frankly, I choose the answer more as respect rather than the truth in it. Because until now I still don't know the right one. Maybe I need more years of learning before I get a firm understanding of the topic itself.

  • 写回答

8条回答 默认 最新

  • douxuanling6523 2010-03-24 12:14
    关注

    OK, justjoe, I see you got confused with this arguement and there is my big part in it.

    Some more explanations for you.

    The answer depends on the task. You have 2 options:

    If you need only one IP address, you can use only REMOTE_ADDR and nothing else. Take a look at the web-server's access log: there is only one IP address and it's REMOTE_ADDR one. At least it guaranteed you a valid IP address. In many cases, like a traffic counter, it's the only thing you can rely on. Thes is general answer to the "How to get an IP address" question.

    If you want to record an address that can be more precise probably - so, no one forbids you from recording many addresses, not one. But of course, you have to record these HTTP headers along with REMOTE_ADDR, not instead of it. There is some use for such a throng of addresses. But you can't rely on it too much. But you can dig some information from it, if you care.

    The only case for the FORWARDED_FOR header is a misconfigured webserver, who place the real IP address into this variable. In this case it can be used as an IP address. But of course it must be done manually, in the every particular case, not as the general recommendation. But anyway I'd quit such a webserver as there can't only be one misconfiguration in it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大