PHP & cURL proxy - how to make multi-user cookie jar?

倖福魔咒の 提交于 2019-12-24 04:05:18

问题


I'm developing an application that does a remote login, amongst other things, via cURL.

The remote site gives out a session cookie, which I can store in my cookie jar.

I want each user to my site to have a unique session on the remote site. My application works fine with just one user (me), but I'm not sure how to make it multiuser.

My first thought is to set a session variable for my application users, then use this variable as the name of the cookie jar, but this seems ugly.

Is there any built-in PHP/cURL functionality that will pass the unique session from the remote server to my users?

Many thanks for any help.

Jack


回答1:


Your question has every element of a solution, namely cookie jar and sessions.

When you provide the cookie jar file to CURL simply give it a name according to your user, example:

$protected_cookie_dir='/cookies/';
$uid=getUser()->id; // get the user id
curl_set_opt($ch,CURLOPT_COOKIEFILE,$protected_cookie_dir.'file_'.$uid.'.data');
curl_set_opt($ch,CURLOPT_COOKIEJAR,$protected_cookie_dir.'jar_'.$uid.'.data');

Important: Be sure to hide that folder (maybe store it outside your document root).



来源:https://stackoverflow.com/questions/5731815/php-curl-proxy-how-to-make-multi-user-cookie-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!