问题复现
主机:192.168.1.28(本机)
执行
browser-sync start --proxy localhost
用node进行转发
index.php 内容:
var_dump($_SERVER['HTTP_HOST']); // 这里是直接dump
var_dump(' '.$_SERVER['HTTP_HOST']); // 这里是拼接了个空格dump
访问
http://192.168.1.28:3000/
得到
/code/index.php:14:string '192.168.1.28:3000' (length=9)
/code/index.php:15:string ' localhost' (length=10)
可以看到 第一次dump 的长度是不对的
后续的对 $_SERVER['HTTP_HOST'] 的字符串操作得到的都是 "localhost" ,并且没有端口号
如何得到 192.168.1.28:3000 这个真实的请求地址?
补充:
如果PHP服务增加端口,如81
node代理为
browser-sync start --proxy 192.168.1.28:81
访问
http://localhost:3000/
则页面输出变为
/code/index.php:14:string '//localhost:3000' (length=15)
/code/index.php:15:string ' 192.168.1.28:81' (length=16)
多了个双斜杠