PHP and cURL proxy - how to make a multi-user cookie?

I am developing an application that does remote login, among other things, via cURL.

The remote site issues a session cookie, which I can store in my cookie bank.

I want every user of my site to have a unique session on a remote site. My application works fine with one user (me), but I'm not sure how to make it multi-user.

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

Is there a built-in PHP / cURL function that will transfer a unique session from a remote server to my users?

Thanks so much for any help.

Jack

+2
source share
1 answer

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

When you provide a cookie cookie in CURL, just give it a name according to your user, for 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 this folder (perhaps save it outside the document root directory).

+3
source

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


All Articles