0
我需要更改PHP在使用file_get_contents()請求文件時發送的標頭。這是可能的還是我將不得不使用CURL?如何更改PHP在外部URL上使用file_get_contents時發送的標頭?
我需要更改PHP在使用file_get_contents()請求文件時發送的標頭。這是可能的還是我將不得不使用CURL?如何更改PHP在外部URL上使用file_get_contents時發送的標頭?
您可以結合使用file_get_contents()與stream_context_create()
例:
<?php
$context = stream_context_create(array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
));
$out = file_get_contents($filename, false, $context);
您將需要使用CURL。它也更可靠。請參閱curl_setopt和CURLOPT_HTTPHEADER。