tags:

views:

55

answers:

3

I have a situation explained in this question (with a bounty, yet with no replies), as the initial plan is not going to work, I have reverted to using file_get_contents, sending cookies alongside to authenticate as a logged in user.

Now the example on PHP manual shows how you can use stream contexts to send a cookie. Here is the excerpt:

Example #4 Using stream contexts

<?php
// 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);
?>

My question is, '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"
+1  A: 

Both aren't correct. You separate them with ;:

Cookie: user=3345; pass=abcd
nikic
A: 

3

Cookie: user=3345; pass=abcd
mvds
A: 

Why don't you use CURL? It is designed for these kind of HTTP problems.

Treffynnon
Because it is too much work compared to the present method.
Majid