简体   繁体   English

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

[英]Laravel's `$request->ip()` doesn't return the last digit of the IP address

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 . 我正在使用Laravel 5,PHP 7和Homestead,由于某种原因,当我尝试访问$request->ip()我返回了192.168.10.1 But in my /etc/hosts file I have 192.168.10.10 homestead.test . 但是在我的/etc/hosts文件中,我有192.168.10.10 homestead.test Then when I var_dump($request); 然后当我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? 有人在从IP地址修剪最后一个值之前看到过这个吗?

In your case, $request->ip() means REMOTE_ADDR , which is the IP( 192.168.10.1 ) your browser is using. 在您的情况下, $request->ip()表示REMOTE_ADDR ,这是您的浏览器使用的IP( 192.168.10.1 )。

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. SERVER_NAMESERVER_ADDRhomestead.test192.168.10.10 ,这是您的虚拟主机的名称和虚拟主机的IP。

One of your computer's IP is 192.168.10.1 , your homestead's IP is 192.168.10.10 . 您计算机的IP之一是192.168.10.1 ,您宅基地的IP是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 . 因此,当您访问PHP程序时,您的浏览器使用192.168.10.1连接到Homestead的192.168.10.10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM