1

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

3
  • Please provide some context to your problem. Commented Dec 7, 2009 at 15:17
  • My problem is that with cURL the cookie is not for the browser, it's for everyone, and it's not cool with a login thing. Does anybody know something that is handling the cookies better than cURL? Commented Dec 7, 2009 at 15:22
  • Note that curl is a command line tool and there are libcurl bindings for just about every imaginable language on the planet. Thus "using curl" can be one of quite many different ways. Are you somehow referring to usage with any of this particular ways or generally? Commented Dec 7, 2009 at 20:33

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

2 Comments

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.
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'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.