douran6443 2018-09-30 02:30
浏览 516
已采纳

Laravel` $ request-> ip()`不返回IP地址的最后一位

I'm using Laravel 5, PHP 7, and Homestead, and for some reason when I try to access $request->ip() I get back 192.168.10.1. But in my /etc/hosts file I have 192.168.10.10 homestead.test. Then when I var_dump($request); I get the following

...
 'HTTP_HOST' => string 'homestead.test' (length=14)
 'REDIRECT_STATUS' => string '200' (length=3)
 'SERVER_NAME' => string 'homestead.test' (length=14)
 'SERVER_PORT' => string '80' (length=2)
 'SERVER_ADDR' => string '192.168.10.10' (length=13)
 ...
 'REMOTE_ADDR' => string '192.168.10.1' (length=12)

Has anyone seen this before where the last value gets trimmed from the IP address?

  • 写回答

1条回答 默认 最新

  • dongren1353 2018-09-30 02:40
    关注

    In your case, $request->ip() means REMOTE_ADDR, which is the IP(192.168.10.1) your browser is using.

    SERVER_NAME and SERVER_ADDR is homestead.test and 192.168.10.10, that's your web host's name and your web host's IP.

    One of your computer's IP is 192.168.10.1, your homestead's IP is 192.168.10.10. So when you access your PHP program, your browser is using 192.168.10.1 to connect to homestead's 192.168.10.10.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog