Problem with sending cookies with file_get_contents
Posted
by Ikke
on Stack Overflow
See other posts from Stack Overflow
or by Ikke
Published on 2008-11-20T19:46:48Z
Indexed on
2010/06/12
0:42 UTC
Read the original article
Hit count: 284
Hi, i'm trying to get the contents from another file with file_get_contents (don't ask why).
I have two files: test1.php and test2.php. Test1.php returns a string, bases on the user that is logged in.
Test2.php tries to get the contents of test1.php and is being executed by the browser, thus getting the cookies.
To send the cookies with file_get_contents, i create a streaming context:
$opts = array('http' => array('header'=> 'Cookie: ' . $_SERVER['HTTP_COOKIE']."\r\n"))`;
I'm retreiving the contents with:
$contents = file_get_contents("http://www.domain.com/test1.php", false, $opts);
But now I get the error:
Warning: file_get_contents(http://www.domain.com/test1.php) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
Does somebody knows what i'm doing wroing here?
edit: forgot to mention: Without the streaming_context, the page just loads. But withouth the cookies I don't get the info I need.
© Stack Overflow or respective owner