title: Pass session information to PHP via curl
body: <p>What I'm trying to do is make the session from the client program available to the server program.</p>
  
  <p>Both programs are running on the same Apache site, so the configuration for the session files, permissions, etc are all the same.</p>
  
  <p><strong>Test server program:</strong></p>
  
  <pre><code>&lt;?php
  session_name('main');
  session_start();
  echo '&lt;pre&gt;'.print_r($_COOKIE, true).'&lt;/pre&gt;';
  ?&gt;
  </code></pre>
  
  <p><strong>Test client program:</strong></p>
  
  <pre><code>&lt;?php
  session_name('main');
  session_start();
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  curl_setopt($ch, CURLOPT_COOKIE, 'main='.session_id());
  curl_setopt($ch, CURLOPT_POSTFIELDS, 'A=1&amp;B=2');
  $result=curl_exec($ch);
  curl_close($ch);
  echo $result;
  ?&gt;
  </code></pre>
  
  <p><strong>Behavior:</strong></p>
  
  <ul>
  <li>As written, the curl call to the server times out. </li>
  <li>If I remove session_start() from the server, the server returns the cookie value as expected.</li>
  <li>When I remove curl_setopt($ch, CURLOPT_COOKIE, 'main='.session_id()) from the client every call to the server creates a new session file as expected.</li>
  <li>I added curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile) making sure that $cookiefile exists and is writable, no change in behavior.</li>
  </ul>
  
  <p>So is this just not possible to do? I don't need to write any cookies or get cookie information back, I just need the server program to be able to access same session information as the client.</p>