0

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);
Bin
  • 1

1 Answers1

0

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?

  • $request->session()->put($key, $params); - not working when call curl to function createSession(), $param is value recevice from request curl send, problem here is missing cookie when call curl to createSession()??? plz – Bin Oct 12 '18 at 08:26