2

I have this

{
  "session":"59a28f4741b0800302147c4e8db00e5e",
  "id":"765611988531745",
  "rememberLogin":"76561198852231745||67b583c48e95a76fbcf7da254714e206"
}

how can I set this cookie to curl headers when i send the POST request?

FunnyCheese
  • 311
  • 1
  • 4
  • 11

1 Answers1

4

Curl cookie is like this: key1=value1; key2=value2;

So you need to convert your json to that. You can use this simple function to do that.

function jsontocookie($json) {
    $ret = "";

    foreach(json_decode($json, true) as $key => $value){
        $ret .= $key."=".$value."; ";
    }

    return $ret;
}

And send with CURLOPT_COOKIE

curl_setopt($ch, CURLOPT_COOKIE, jsontocookie($yourJsonData));
Ugur Eren
  • 1,968
  • 2
  • 11
  • 21