CodeIgniter Forums
Passing cookies (multiple) through file_get_contents() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Passing cookies (multiple) through file_get_contents() (/showthread.php?tid=46594)



Passing cookies (multiple) through file_get_contents() - El Forum - 11-07-2011

[eluser]skunkbad[/eluser]
Just trying to pass all cookies through to another script, but even though $opts array looks good, apache_request_headers() in the receiving script doesn't show the cookies. Are they being destroyed by CI or something:

Code:
public function index()
{
$opts['http']['method'] = 'GET';

$opts['http']['user_agent'] = $_SERVER['HTTP_USER_AGENT'];

if( count( $_COOKIE ) > 0 )
{
  $cookie_string = 'Cookie: ';

  $i = 1;

  foreach( $_COOKIE as $k => $v )
  {
   if( $i !== 1 )
   {
    $cookie_string .= '; ';
   }

   $cookie_string .= $k . '=' . urlencode( $v );

   $i++;
  }

  $opts['http']['header'][] = $cookie_string;
}

$context = stream_context_create( $opts );

echo file_get_contents( 'http://domain.com/my_script', FALSE, $context );
}

PHP has curl wrappers, so that's why header in array