PHP stream_context_get_default() overrides default context
PHP has a function named stream_context_set_default(), however, another function stream_context_get_default() overrides default contexts too.
$default_opts = [
  'http' => [
    'method' => "GET",
    'header' => "Accept-language: en\r\nCookie: foo=bar"
  ]
];
$default = stream_context_get_default($default_opts);
readfile('http://localhost');The server will get an request includes:
[
  "Accept-language" => "en",
  "Cookie" => "foo=bar"
]Written by Yaodong Zhao
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Php 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#

 
 
 
 
