sKunKbad Posted November 8, 2011 Share Posted November 8, 2011 I've been trying to pass a cookie along to one of my sub domains, and the I'm getting an error: An error #2 occurred in script 'C:\xampp\htdocs\optifit-hcg\application\controllers\test.php' on line 66: file_get_contents(http://localhost.optifit-hcg/horz_text_menu) [function.file-get-contents]: failed to open stream: HTTP request failed! The idea is that the script on the sub domain would return some data based on the cookie contents, but when I print_r() both $_SESSION and $_COOKIE the arrays are blank. Please let me know if you see anything wrong: $opts['http']['method'] = 'GET'; $opts['http']['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $cookie_string = 'Cookie: '; // If there are cookies, send them with the request if( count( $_COOKIE ) > 0 ) { $i = 1; foreach( $_COOKIE as $k => $v ) { if( $i !== 1 ) { $cookie_string .= '; '; } $cookie_string .= $k . '=' . urlencode( $v ); $i++; } // Development environment not compiled with curl wrappers if( ENVIRONMENT != 'development' ) { $opts['http']['header'][] = $cookie_string; } else { $opts['http']['header'] = $cookie_string; } } $context = stream_context_create( $opts ); $contents = file_get_contents( 'http://localhost.optifit-hcg/horz_text_menu', FALSE, $context ); echo $contents; Link to comment https://forums.phpfreaks.com/topic/250673-stream_context_create-and-disappearing-cookies/ Share on other sites More sharing options...
sKunKbad Posted November 8, 2011 Author Share Posted November 8, 2011 Turns out that since the requesting script and the requested script were both using sessions, I had to use session_write_close() before file_get_contents(). Link to comment https://forums.phpfreaks.com/topic/250673-stream_context_create-and-disappearing-cookies/#findComment-1286130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.