HaLo2FrEeEk Posted April 18, 2010 Share Posted April 18, 2010 I've been using stream_context_create() to send cookies along with a file_get_contents() 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: <?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; ?> This will utilize a quick script that I wrote that displays the values of 2 cookies named "testcookie" and "testcookie2". 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: $cookies = array("Cookie: testcookie=blah; path=/; domain=infectionist.com;", "Cookie: testcookie2=haha; path=/; domain=infectionist.com;"); 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! Quote Link to comment https://forums.phpfreaks.com/topic/198900-sending-cookies-with-file_get_contents/ Share on other sites More sharing options...
HaLo2FrEeEk Posted April 19, 2010 Author Share Posted April 19, 2010 Bump! Why is it that every question I ask here isn't getting answered? Seriously the last like, 4 questions I've asked have been completely ignored! Quote Link to comment https://forums.phpfreaks.com/topic/198900-sending-cookies-with-file_get_contents/#findComment-1044432 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.