Jump to content

Recommended Posts

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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.