Call me out if this is a duplicate question, but this is starting to get ridiculous. I want to, with PHP:
GET http://www.example.com/hello.xyz
And add this header to the request:
"X-Header-Name: $foobar"
where foobar comes from a php variable that is already defined.
and then store the response in a variable. That's it! Nothing more, nothing less.
But I can't find it!
I don't want to use curl or anything like that, it'd slow it down too much if I run curl everytime. Edit: My main concern with using curl is about compatibility with Windows (local server) vs. Linux (deployment server).
<?php
echo "So, how do I do it in the simplest way possible?";
?>
You may use file_get_contents if you don't want to use curl but not sure about speed but it's
php
's built in function wherecurl
is not. When talking aboutspeed
then I think whatever you use for a remote request, the speed/performance will depend on the network connection speed more than the function/library and maybe there is a bit different among these (curl/file_get_contents/fsockopen) but I think it'll be a very little (1-2 %) and you can't catch the difference, it'll seem almost same.Also, if you want to use
curl
then you may use thisAlso, check this answer, it may help you to decide.