开发者

Curl cookie handling

Is that possible that with cURL not every user use the sam开发者_Go百科e cookie?

Because it's cool that I store the cookie that I get, but this cookie will be used by everybody, and it should be, because it's a login cookie.

Charlie


Here's a really basic overview of how cookies work

  1. Client (browser) makes request

  2. Server sees request and asks "hey, did this client send me a cookie?"

  3. Server doesn't see a cookie, so it does some stuff, and then sends back a response, with a cookie

  4. Client (browser) sees the response and says "hey look, a cookie for me, I better save this"

  5. The next time the client makes a request to that same server, it sends along that same cookie

  6. Server sees the request and asks "hey, did this client send me a cookie?"

  7. Server sees the cookie this time, and does some different stuff because of what's in the cookie, and then sends back a response, with a cookie

  8. Client (browser) sees the response and says "hey look, a cookie for me, lets update the one I have"

It sounds like the problem you're running into is you have multiple curl requests running from the same machine, but you want each one to use a different cookie file.

You should be able to achieve this by using the following two curl options

CURLOPT_COOKIEJAR   //tells curl which file to save the cookie from the server in
CURLOPT_COOKIEFILE  //tells curl which file to look in and send as the request cookie

If you setup a system so that each different curl request is setting a different path value for these two options, you should be set.


Your question is unclear, do you want all user to use the same cookie or not ? What is an user in your case, a visitor on your website ?

In any case, you can set which file curl will use to save/load its cookies using curl_setopt and the CURLOPT_COOKIE* constants.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜