dongwu9647 2019-07-14 11:20
浏览 990

通过PHP获取HTTP请求头中的代理服务器IP和端口

I have a website that is being accessed by internal people to the organisation. The organisation is using a proxy for using the Internet. The proxy server has a static IP (say 10.12.13.14) and port (3128). I want to check whether any request on my website home page is through the proxy server. I believe that the IPs during transfer via multiple gateway/hops or a proxy server are stored in the HTTP request headers (encapsulated).

My Environment details: PHP v5.6 Apache v2.4

Also, I have tried other methods answered here at stackoverflow as well but no help.

Method 1:

$proxy_headers = array(
        'HTTP_VIA',
        'HTTP_X_FORWARDED_FOR',
        'HTTP_FORWARDED_FOR',
        'HTTP_X_FORWARDED',
        'HTTP_FORWARDED',
        'HTTP_CLIENT_IP',
        'HTTP_FORWARDED_FOR_IP',
        'VIA',
        'X_FORWARDED_FOR',
        'FORWARDED_FOR',
        'X_FORWARDED',
        'FORWARDED',
        'CLIENT_IP',
        'FORWARDED_FOR_IP',
        'HTTP_PROXY_CONNECTION'
    );
    foreach($proxy_headers as $x){
        if (isset($_SERVER[$x])) die("You are using a proxy!");
    }

Method 2:

$ports = array(8080,80,81,1080,6588,8000,3128,553,554,4480);  // See Note
    foreach($ports as $port) {
         if (@fsockopen($_SERVER['REMOTE_ADDR'], $port, $errno, $errstr, 30)) {
              die("You are using a proxy!");
         }
     }

Note: Don't know why he made an array of all ports so I removed all and kept 3128 only but it is then showing all request as non-proxied requests even when I am accessing it through the proxy.

I want to detect whether the person is from the proxy network or not and my logic is to check for proxy server IP i.e. 10.12.13.14 or Port i.e. 3128 in the headers through PHP. Currently, it is showing all request as non-proxied requests even when I am accessing it through the proxy.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥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,如何解決?