PHP伪造referer访问地址

 1、方法一(CURL):

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "https://www.jiansouti.com");
curl_setopt ($ch, CURLOPT_REFERER, "https://www.jiansouti.com");
curl_exec ($ch);
curl_close ($ch);

2、方法二(fsockopen):

$server = 'www.jiansouti.com';
$host = 'www.jiansouti.com';
$target = 'api.php';
$referer = 'https://www.jiansouti.com/'; // Referer 
$port = 80;
$fp = fsockopen($server, $port, $errno, $errstr, 30);
if (!$fp){
    echo "$errstr ($errno)\n";
}else{
    $out = "GET $target HTTP/1.1\r\n";
    $out .= "Host: $host\r\n";
    $out .= "Referer: $referer\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)){
        echo fgets($fp, 128);
    }
    fclose($fp);
}

 

posted @ 2021-12-21 19:15  MRtanchen  阅读(100)  评论(0编辑  收藏  举报