获取 IP 地址记录
第一种:直接 $request->getClientIp()
查询本机 IP :
访问域名: http://atest.woaap.com:11035/miniapp/api/userPlatform
获取到的 IP :211.95.41.68
Nginx 反向代理,访问域名: https://atest.woaap.com/proxy_11035/miniapp/api/userPlatform
获取到的 IP : 127.0.0.1
第二种
以下二选一:
$request->setTrustedProxies(array('10.32.0.1/16'));
$request->setTrustedProxies($request->getClientIps());
return $ip = $request->getClientIp();
访问域名: http://atest.woaap.com:11035/miniapp/api/userPlatform
获取到的 IP :211.95.41.68
Nginx 反向代理,访问域名: https://atest.woaap.com/proxy_11035/miniapp/api/userPlatform
获取到的 IP : 127.0.0.1
伪造 IP 地址
伪造 curl -H "X-Forwarded-For: 192.168.1.1, 192.168.1.2, 192.168.1.3"
构造URL:
curl -H "X-Forwarded-For: 192.168.1.1, 192.168.1.2, 192.168.1.3" -d "session_id=38oUb11ePu9ZyReY3tkTzn2BQVLOl7z7NqhXv51S1r5KGrBAikmUh1XIhUmeROmF5ece0e30196d5&openid_share=123123123&platform=888" "https://atest.woaap.com/proxy_11035/miniapp/api/userPlatform"
最后拿到的就是 192.168.1.3