tags:

views:

328

answers:

2

Hello!

Is that possible that with cURL not every user use the same 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

+2  A: 

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.

Lepidosteus
So, I login in one computer (through an API), curl stores the cookie well, BUT on an other computer I don't have to login, because it uses the same cookie, and I don't want that.
Charlie
Then somehow create an identifier to know which 'computer' the request is coming from, then use that identifier in the filename you give to CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR. That way the cookie file will change for each 'computer'.
Lepidosteus
A: 

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.

Alan Storm