Location: PHPKode > scripts > HTTP Cookie > http-cookie/example.php
<pre>
<?php
require_once('httpcookie.php');

/*
	Get some HTTP headers from an URL to test the class, 
	you may also try the variable $http_response_header
	( see PHP manual )
*/

$url = 'http://msn.com';
$headers = get_headers($url);
print_r($headers);

/*
	Parse cookies from the HTTP headers, call the method
	of the class statically. Note that the 2nd arg for 
	the method is the ORIGINAL URL that returned the 
	HTTP headers.
*/

$cookies = httpcookie::parse($headers, $url);
print_r($cookies);

/*
	Rebuild cookie from the cookies array, call the 
	method of the class statically. Cookie can be
	built for different URLs.
*/

$cookie[0] = httpcookie::build($cookies, $url);
$cookie[1] = httpcookie::build($cookies, 'http://www.msn.com');
print_r($cookie);

/*
	Make a HTTP request with the returned cookie
*/

$options = array(
	'http'=>array(
	'method' => "GET",
	'header' => 
		"Content-type: application/x-www-form-urlencoded\r\n".
		"Cookie: ".$cookie[1]."\r\n"
	)
);
$context = stream_context_create($options);
$html = file_get_contents('http://www.msn.com', 0, $context);
?>
</pre>
Return current item: HTTP Cookie