I need to change the headers that PHP sends when it requests a file using file_get_contents(). Is that possible or would I have to use CURL?
Asked
Active
Viewed 251 times
2 Answers
5
You can use file_get_contents() in conjunction with stream_context_create()
Exemple :
<?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);

Xavier Barbosa
- 3,919
- 1
- 20
- 18
0
You will need to use CURL. It's also more reliable. See curl_setopt and CURLOPT_HTTPHEADER.

Antti Rytsölä
- 1,485
- 14
- 24