Sorry, I messed that up a bit. Snoopy does not store it's headers in an associative array, so $snoopy->headers['setCookies'] will not work (you will need to use numbers to find your headers, i.e. $snoopy->headers[4]; or something), however print_r($snoopy->headers); should print out all the headers of the return packet. Here is my code to display returned headers:
Code: Select all
function displayHeader()
{
global $snoopy;
echo "<PRE>\nHeaders: \n";
print_r($snoopy->headers);
echo "\n</PRE>\n";
}
Also, here is a function that reformats returned headers into an associative array:
Code: Select all
function reformHeaders($header)
{
$a = array();
$cookiecnt = 0;
foreach ($header as $key => $value)
{
$colpos = strpos($value, ':');
if ($value != '\n')
{
if (substr($value, 0, 10) == 'Set-Cookie')
{
$a['Set-Cookie'][substr($value, 12, strpos($value, '=') - 12)] = substr($value, strpos($value, '=')+1);
$cookiecnt++;
}
elseif ($colpos !== false)
{
$a[substr($value, 0, strpos($value, ':'))] = substr($value, strpos($value, ':')+2);
}
else
{
$a[$key] = $value;
}
}
}
return $a;
}
function displayRefHeader()
{
global $snoopy;
echo "<PRE>\nReformed: \n";
print_r(reformHeaders($snoopy->headers));
echo "\n</PRE>\n";
}
using these functions I get:
Headers:
Array
(
[0] => HTTP/1.1 302 Moved Temporarily
[1] => Server: Apache-Coyote/1.1
[2] => Set-Cookie: JSESSIONID=A0E1BF4C9B865A33354FC94AB2DC80F1; Path=/
[3] => Location: (removed here for privacy concerns)
[4] => Content-Type: text/html
[5] => Content-Length: 0
[6] => Date: Mon, 27 Nov 2006 20:34:15 GMT
)
Reformed:
Array
(
[0] => HTTP/1.1 302 Moved Temporarily
[Server] => Apache-Coyote/1.1
[Set-Cookie] => Array
(
[JSESSIONID] => A0E1BF4C9B865A33354FC94AB2DC80F1; Path=/
)
[Location] => (removed here for privacy concerns)
[Content-Type] => text/html
[Content-Length] => 0
[Date] => Mon, 27 Nov 2006 20:34:15 GMT
)
Fell free to use this code as long as it is not in a commercial product.