开发者

How do I change the headers that PHP sends when using file_get_contents on an external URL?

开发者 https://www.devze.com 2023-02-06 11:28 出处:网络
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 CUR开发者_开发问答L?You can use file_get_contents() in conjunctio

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 CUR开发者_开发问答L?


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


You will need to use CURL. It's also more reliable. See curl_setopt and CURLOPT_HTTPHEADER.

0

精彩评论

暂无评论...
验证码 换一张
取 消