dongshou2024 2018-10-12 04:27
浏览 39

从curl请求参数后不创建新会话

I have curl to the function initialized session 1 with the element to transfer from curl, but at this function cannot re initialize new session 1 with the key and value got from curl. However when I execute F5 at the link link which curl call to which is not over curl, still initialized session, please make me

public function createSession(){
$params = $request->all();
        $key = uniqid();
        $request->session()->put($key, $params);
        return response()->json([
            'success' => true,
            'key' => $key,
        ]);
}

Curl:

$ch = curl_init($url);
        curl_setopt($ch, CURLOPT_POST, count($params));
        curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); // Time out 60s
        curl_setopt($ch, CURLOPT_TIMEOUT, 60); // connect time out 60s

        $result = curl_exec($ch);
        $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        if (curl_error($ch)) {
            return false;
        }

        if ($status != 200) {
            curl_close($ch);
            return false;
        }
        // close curl
        curl_close($ch);
        return json_decode($result);
  • 写回答

1条回答 默认 最新

  • dongzhui2636 2018-10-12 05:47
    关注

    The server needs the Session ID in order to identify the data from the previous call. When you use the browser, that Session ID is stored in a Cookie that is automatically sent to the server. When you use cURL you need to manually set the cookie.

    See this answer for a better understanding of how Sessions and Cookies work: How do Cookies and Sessions work?

    See this answer for an example of using cookies in curl for php: How can I send cookies using PHP curl in addition to CURLOPT_COOKIEFILE?

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?