PHP& cURL代理 - 如何使多用户cookie罐? [英] PHP & cURL proxy - how to make multi-user cookie jar?

查看:201
本文介绍了PHP& cURL代理 - 如何使多用户cookie罐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个通过cURL进行远程登录的应用程序。

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

远程站点发出会话cookie,我可以存储

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.

我的第一个想法是为我的应用程序用户设置一个会话变量,然后使用这个变量作为cookie jar的名称,但这看起来很丑陋。

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.

是否有任何内置的PHP / cURL功能,可将远程服务器的唯一会话传递给我的用户?

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

非常感谢您的帮助。

杰克

推荐答案

您的问题有解决方案的每一个元素,即cookie jar和会话。

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

当您提供cookie jar文件到CURL只需给一个名称根据您的用户,示例:

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).

这篇关于PHP& cURL代理 - 如何使多用户cookie罐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆