简体   繁体   中英

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 response 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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM