Source Code:
(back to article)
<?php // Define custom HTTP headers $options = [ 'http' => [ 'method' => "GET", 'header' => "Accept-language: en\r\n" . "Cookie: foo=bar\r\n", ], ]; // Create a stream context with the custom headers $context = stream_context_create($options); // Make an HTTP GET request to a URL that returns data and pass in the stream context $file = file_get_contents('http://jsonplaceholder.typicode.com/posts', false, $context); // Output the response echo $file; ?>
Result:
Report an issue