curl cookie处理 [英] Curl cookie handling
问题描述
有可能cURL不是每个用户都使用相同的cookie吗?
因为很酷,我存储我获得的cookie,但这个cookie将被使用
Charlie
服务器看到请求并询问这个客户端是否向我发送了一个Cookie?
看到一个Cookie,然后发送回一个响应,并发送一个Cookie
客户端
下次客户端向同一个服务器发出请求时,它会沿着同一个cookie发送
伺服器看到这项要求,并询问「这位客户是否向我发送了Cookie? >
伺服器这次看到Cookie,因为Cookie中有什么,所以做了一些不同的处理,然后传回回应,并附上Cookie
客户端(浏览器)看到响应,并说看起来,一个cookie为我,更新我有一个
听起来你遇到的问题是你有多个curl请求从同一台机器运行,但你想要每个人使用不同的cookie文件。
您应该能够通过使用以下两个curl选项来实现这一点。
CURLOPT_COOKIEJAR //告诉curl哪个文件保存cookie从
CURLOPT_COOKIEFILE //告诉curl要查找哪个文件并作为请求cookie发送
如果您设置系统以使每个不同的curl请求为这两个选项设置不同的路径值,则应设置。
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
Here's a really basic overview of how cookies work
Client (browser) makes request
Server sees request and asks "hey, did this client send me a cookie?"
Server doesn't see a cookie, so it does some stuff, and then sends back a response, with a cookie
Client (browser) sees the response and says "hey look, a cookie for me, I better save this"
The next time the client makes a request to that same server, it sends along that same cookie
Server sees the request and asks "hey, did this client send me a cookie?"
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
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.
这篇关于curl cookie处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!