The example on PHP manual shows how you can use stream contexts to send a cookie. Here is the excerpt:
// Create a stream $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en\r\n" . "Cookie: foo=bar\r\n" ) ); $context = stream_context_create($opts); // Open the file using the HTTP headers set above $file = file_get_contents('http://www.example.com/', false, $context);
How do you send more than one cookie? Like #1 or #2, or what?
#1
"Cookie: user=3345&pass=abcd\r\n"
#2
"Cookie: user=3345\r\n" . "Cookie: pass=abcd\r\n"
This is old topic but on my last test on one my API, cURL is faster and more stable. Sometimes file_get_contents on larger request need over 5 seconds when cURL need only from 1.4 to 1.9 seconds what is double faster.
The function returns the read data or false on failure. This function may return Boolean false , but may also return a non-Boolean value which evaluates to false .
The file_get_contents() reads a file into a string. This function is the preferred way to read the contents of a file into a string. It will use memory mapping techniques, if this is supported by the server, to enhance performance.
#3
Cookie: user=3345; pass=abcd
Both aren't correct. You separate them with ;
:
Cookie: user=3345; pass=abcd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With