douzhai7873 2012-03-17 19:02
浏览 66
已采纳

在mysql中存储卷曲会话cookie

I was wondering if it was possible to store a curl's session cookie inside of mysql.

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

get_the_cookie() returns a unique-to-user.txt file path, but I want to be able to store this cookie in a mysql instead of the file-system if its even possible.

  • 写回答

1条回答 默认 最新

  • duanhe1976 2012-03-17 19:06
    关注

    cURL does not allow you to do this directly, but you can fake it by creating temporary files for the duration of the request and manually transferring their contents from/to the database as needed.

    For example:

    $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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 机器学习教材中的例题询问
  • ¥15 求.net core 几款免费的pdf编辑器
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题
  • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)