title: curl json does not save cookiefile PHP
body: <p>I can't save cookiefile when I use curl login with json in any hosting. Here is my code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  function curl($url = false, $var = false, $cookie = false, $header = false)
  {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
          if($var){
    curl_setopt($ch, CURLOPT_POSTFIELDS,$var);
          }
          curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); 
    curl_setopt($ch, CURLOPT_REFERER, $header);
    @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);  
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
     'Content-Type: application/json',
              'charset=utf-8',
     'Content-Length: ' . strlen($var)
          )); 
    $error = curl_error($ch);
    $result = curl_exec($ch);
    curl_close ($ch);
    return $result;
          return $error;
  }
      $urlcheck = 'http://abcxyz.com/api/login';
      $username = 'xxxxxxxx';
      $password = 'xxx';
      $passmd5 = @md5($password);
   $request = '{"username":"'.$username.'","password":"'.$password.'","passwordMD5":"'.$passmd5.'"}';
   $data = json_decode($request);
   if (empty($data-&gt;username) || empty($data-&gt;password)){
    echo " Thieu du lieu";
   }else{
    $ck = str_replace('\\','/',dirname(__FILE__)).'/cookies/'.$data-&gt;username.'.txt'; 
          $curl = curl($urlcheck,$request,$ck);
          echo $curl; 
    }
  ?&gt;</code></pre>
  </div>
  </div>
  
  I've chmod 0777 directory /cookies/.</p>