Reading the Set-Cookie instructions in an HTTP Response header
Is there any standard means in PHP to read the Set-Cookie
instructions in an HTTP Response header, without manually parsing it?
More specifically, I want to read the value of the ASP.NET_SessionId
cookie returned by an ASP.NET Web Service I am consuming.
EDIT:
I am consuming the Web Service using PHP's native SoapClient
class. I can use the __getLastResponseHeaders()
method to retrieve the whole of the HTTP respon开发者_JAVA技巧se header returned by the Web Service:
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
Set-Cookie: ASP.NET_SessionId=ku501l55o300ik3sa2gu3vzj; path=/; HttpOnly
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Tue, 11 Jan 2011 23:34:02 GMT
Content-Length: 368
But I want to extract the value of the ASP.NET_SessionID
cookie:
ku501l55o300ik3sa2gu3vzj
And, of course, I don't want to do it manually.
Try this:
$_COOKIE['ASP.NET_SessionId'];
Or this:
$cookies = getCookies();
$sessionId = $cookies['ASP.NET_SessionId'];
Not sure if the last part will work correctly - if it does not, you could try:
print_r($cookies);
to see if it even returns anything.
You can view the cookies returned via SOAP client by using:
var_dump($client->_cookies);
echo "cookie is ".$client->_cookies["ASP.NET_SessionId"][0];
精彩评论