1、方法一(CURL):
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "https://www.51dev.com");
curl_setopt ($ch, CURLOPT_REFERER, "https://www.51dev.com");
curl_exec ($ch);
curl_close ($ch);
2、方法二(fsockopen):
$server = 'www.51dev.com';
$host = 'www.51dev.com';
$target = 'api.php';
$referer = 'https://www.51dev.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);
}