开发者

Curl: Multiple Cookies

开发者 https://www.devze.com 2023-03-17 17:27 出处:网络
How can I have multiple cookies for each Client/PC to run a script? If ComputerA run a script then cookies开发者_JS百科.txt will be created and also ComputerB run same Script then cookies.txt will be

How can I have multiple cookies for each Client/PC to run a script?

If ComputerA run a script then cookies开发者_JS百科.txt will be created and also ComputerB run same Script then cookies.txt will be over written which is bad.

Example:

curl_setopt($ch,CURLOPT_COOKIEFILE,"cookie.txt");
curl_setopt($ch,CURLOPT_COOKIEJAR,"cookie.txt");


If they're seperate computers, then it's seperate file systems and each will have its own cookie file.

But if you're on shared storage, then use a dynamic filename, perhaps

'cookie-' . $_SERVER['SERVER_NAME'] . '.txt'

instead, which'd give you

cookie-ComputerA.txt    cookie-ComputerB.txt    etc...


You could hash the IP that the request comes from and add that to the filename. This would work unless both computers have the same public IP.


You can use a unique identifier to uniquely identify user. User id, session ID or IP address may be a good choice:

$user_id = get_user_id_from_somewhere();
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie-".$user_id.".txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie-".$user_id.".txt");
0

精彩评论

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