Function prototype: resource stream_context_create ([array $ options [, array $ params])
View instances
// Define the options array
$ Opts = array
(
'Http' => array
(
'Method' => "get ",
'Header' => "accept-language: enrn". "cookie: foo = barrn"
)
);
// Create a data stream context
$ Context = stream_context_create ($ opts );
/* Send an http request to the specified address
The request contains the additional header information */
$ Fp = fopen ('http: // www.111cn.net ', 'R', false, $ context );
// Output all data at the file pointer
Fpassthru ($ fp );
// Close the file
Fclose ($ fp );
/*
The output result of this code is: cookie value of the request
Array
(
[Foo] => bar
)
*/
Instance 2
$ Default_opts = array
(
'Http' => array
(
'Method' => "get ",
'Header' => "accept-language: enrn". "cookie: foo = bar ",
'Proxy' => "tcp: // 10.54.1.39: 8000"
)
);
$ Alternate_opts = array
(
'Http' => array
(
'Method' => "post ",
'Header' => "content-type: application/x-www-form-urlencodedrn". "content-length:". strlen ("baz = bomb "),
'Content' => "baz = bomb"
)
);
$ Default = stream_context_get_default ($ default_opts );
$ Alternate = stream_context_create ($ alternate_opts );
/* Sends a regular get request to proxy server at 10.54.1.39
* For www.example.com using context options specified in $ default_opts
*/
Readfile ('http: // www.example.com ');
/* Sends a post request directly to www.example.com
* Using context options specified in $ alternate_opts
*/
Readfile ('http: // www.example.com ', false, $ alternate );