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);

}
file_get_contents方法:
$refer = 'http://www.51ask.org/';

$opt=array('http'=>array('header'=>"Referer: $refer"));

$context=stream_context_create($opt);

$file_contents = file_get_contents($url,false, $context);

0 个评论

要回复文章请先登录注册