如何用PHP有效的伪造HTTP_REFERER

    $host = "www.mysite.com";    
    $file = "formprocess.php";
    $hdrs = array( 'http' => array(
        'header' => "accept-language: en\r\n" .
            "Host: $host\r\n" .
            "Referer: http://$host\r\n" .
            "Content-Type: text/plain\r\n"
        )
    );
    $context = stream_context_create($hdrs);
    $fp = fopen("http://" . $host . "/" . $file, 'r', false, $context);
    fpassthru($fp);
    fclose($fp);

伪造referer主要为了突破防盗链和采集的

除了可以用CURL和sock伪造来源外,还有哪些方法和思路呢?
因为CURL和sock是可以被检测出来的

除了之外,还可以使用file_get_contents来伪造HTTP_REFERER

    $option = array(
    'http' => array(
    'header' => "Referer:$refer")
    );
    //$refer就是伪造的HTTP_REFERER信息URL。
    file_get_contents($url, false,stream_context_create($option));

利用它的第三个参数。要说明的是第三个参数是在PHP5.0.0以后才支持的,之前的版本没这个参数!

也可以使用工具来做,比如fiddler之类的。

 

原文地址:https://www.cnblogs.com/coolid/p/2792626.html