title: Cookies PHP CURL store in clients side
body: <p>I have proxy, and i want to store <code>cookies</code> in clients <code>cookies</code> but when i using the following code its dont works, they dont stores in browser, and if they store somewhere in server anyway they dont works.</p>
  
  <pre><code>$responseInfo = curl_getinfo($ch);
  $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  curl_close($ch);
  $responseHeaders = substr($response, 0, $headerSize);
  preg_match_all("/Set-Cookie: (.*?)=(.*?);/i",$responseHeaders,$cookies);
  array_shift($cookies); //removes first
  $i = 0;
  foreach($cookies[0] as $name) {
      $curl_cookies .= $name."=".$cookies[1][$i].";";
  
  //  if(!isset($_COOKIE[$name])) {
  //      setcookie( $name, $cookies[1][$i], time()+(60*60*24*30) );
  //  }
  //  elseif($_COOKIE[$name] != $cookies[1][$i]) {
  //      setcookie( $name, $cookies[1][$i], time()+(60*60*24*30) );      
  //  }
  
      $i++;
  }
  curl_setopt($ch, CURLOPT_COOKIE, $curl_cookies);
  </code></pre>
  
  <p>When i using  commented code, and remove </p>
  
  <p><code>$curl_cookies .= $name."=".$cookies[1][$i].";";</code></p>
  
  <p><em>and</em></p>
  
  <p><code>curl_setopt($ch, CURLOPT_COOKIE, $curl_cookies);</code></p>
  
  <p>Cookies are stores in the clients <code>cookies</code> but dont works from websites too.
  But when i replace that code to :</p>
  
  <pre><code>  curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
  </code></pre>
  
  <p>All works fine, but <code>cookies</code> are the same for any user, ofc i can use something like </p>
  
  <pre><code>curl_setopt($ch, CURLOPT_COOKIEFILE, $ip."cookie.txt");
  </code></pre>
  
  <p>But that way is makes large count of <code>.txt</code> files for each <code>ip</code> which visit my proxy.</p>
  
  <p>Any idea how to storage <code>cookies</code> into <strong>clients</strong> <code>cookies</code> and make them work?</p>