PHP file_get_contents() and setting reques

2019-01-01 05:34发布

With PHP, is it possible to send HTTP headers with file_get_contents() ?

I know you can send the user agent from your php.ini file. However, can you also send other information such as HTTP_ACCEPT, HTTP_ACCEPT_LANGUAGE, and HTTP_CONNECTION with file_get_contents() ?

Or is there another function that will accomplish this?

标签: php header
7条回答
余生请多指教
2楼-- · 2019-01-01 06:15

Yes.

When calling file_get_contents on a url, one should use the stream_create_context function, which is fairly well documented on php.net

This is more or less exactly covered on the following page at php.net in the user comments section: http://php.net/manual/en/function.stream-context-create.php

查看更多
登录 后发表回答