PHP伪造referer地址

这里分别介绍CURL、SOCKET、file_get_contents实现方法,详细代码如下:
 
CURL方式:
$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, "http://www.51ask.org/";);

curl_setopt ($ch, CURLOPT_REFERER, "http://www.51ask.org/";);

curl_exec ($ch);

curl_close ($ch);
SOCKET方式:
$server = 'www.51ask.org';

$host = 'www.51ask.org';

$target = 'index.php';

$referer = 'http://www.51ask.org/'; // 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)