I've been using stream_context_ create() to send cookies along with a file_get_conten ts() call when requesting a remote page. This is useful if I need to pass information to the remote page that my server can't pass, like a login form. This works perfectly well when I've got a single cookie, or multiple cookies on the same domain and path, but what if I need to send multiple cookies that work for multiple different domains or paths?
Here's an example code:
This will utilize a quick script that I wrote that displays the values of 2 cookies named "testcookie " and "testcookie 2". Notice in the cookies array, I've got both cookies set, and since both work on the same path and domain, they both appear properly. But I've got a page that I need to retrieve while sending multiple cookies from multiple domains (actually subdomains of the requested domain) and/or paths.
How might I accomplish this? I tried making my cookies array have multiple values, like this:
But that didn't work, only the first cookie was set. I can't seem to figure out how this might be done, but I'm sure someone else has done it before. Any help with this will be greatly appreciated!
Here's an example code:
Code:
<?php $cookies = array("Cookie: testcookie=blah; testcookie2=haha; path=/; domain=infectionist.com;"); $opts = array('http' => array('header' => $cookies)); $context = stream_context_create($opts); $html = file_get_contents("http://infectionist.com/misc/testing/cookie.php?do=view", false, $context); echo $html; ?>
How might I accomplish this? I tried making my cookies array have multiple values, like this:
Code:
$cookies = array("Cookie: testcookie=blah; path=/; domain=infectionist.com;", "Cookie: testcookie2=haha; path=/; domain=infectionist.com;");
Comment