Cookie correction

Is it possible that with cURL not every user uses the same cookie?

Because it’s great that I keep the cookie that I receive, but this cookie will be used by everyone, and this should be because it is a cookie for login.

Charlie

+1
source share
2 answers

Here is a really basic overview of how cookies work.

  • Client (browser) makes a request

  • The server sees the request and asks: "Hey, did this client send me cookies?"

  • The server does not see the cookie, so it takes some action and then sends a response with the cookie

  • The client (browser) sees the answer and says: "Hey, look, cookies for me, I better save him"

  • The next time a client sends a request to the same server, it will send the same cookie

  • The server sees the request and asks: "Hey, did this client send me cookies?"

  • The server sees the cookie this time and does some different things because of the cookie, and then sends a response with the cookie

  • The client (browser) sees the answer and says: β€œHey, look, cookies for me, let me update the one I have”

It seems that the problem you are facing is that you have multiple curl requests running on the same computer, but you want each one to use a different cookie.

You should be able to achieve this using the following two curling 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 configure the system so that every other hang request sets a different path value for these two parameters, you must be set.

+3
source

Your question is not clear, do you want all users to use the same cookie or not? What is a user in your case, a visitor to your site?

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

+2
source

Source: https://habr.com/ru/post/906040/


All Articles