gpt4 book ai didi

php - 在 mysql 中存储 curl session cookie

转载 作者:行者123 更新时间:2023-11-29 04:52:48 25 4
gpt4 key购买 nike

我想知道是否可以将 curl 的 session cookie 存储在 mysql 中。

curl_setopt($ch, CURLOPT_COOKIEJAR, get_the_cookie());
curl_setopt($ch, CURLOPT_COOKIEFILE, get_the_cookie());

get_the_cookie() 返回一个 unique-to-user.txt 文件路径,但如果可能的话,我希望能够将此 cookie 存储在 mysql 而不是文件系统中。

最佳答案

cURL 不允许您直接执行此操作,但您可以通过在请求期间创建临时文件并根据需要手动将其内容从数据库传输到数据库来伪造它。

例如:

$cookiejar = // get cookies from database
$cookiejarfile = tempnam(sys_get_temp_dir());
$cookiefile = tempnam(sys_get_temp_dir());
file_put_contents($cookiejarfile, $cookiejar);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejarfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);

$newcookies = file_get_contents($cookiefile);

// and now save cookies to database and clean up temp files

关于php - 在 mysql 中存储 curl session cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9752857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com