title: share the same cookie between two website using PHP cURL extension
body: <p>I want to get the contents of some emails in my gmail account. I would like to use the PHP cURL extension to do this. I followed these steps in my first try:</p>
  
  <ol>
  <li>In the PHP code, output the contents of <a href="https://www.google.com/accounts/ServiceLoginAuth" rel="nofollow noreferrer">https://www.google.com/accounts/ServiceLoginAuth</a>.</li>
  <li>In the browser, the user input username and password to login.</li>
  <li>In the PHP code, save cookies in a file named cookie.txt.</li>
  <li>In the PHP code, send request to <a href="https://mail.google.com/" rel="nofollow noreferrer">https://mail.google.com/</a> along with cookies retrieved from cookie.txt and output the contents.</li>
  </ol>
  
  <p>The following code does not work:</p>
  
  <pre><code>$login_url = 'https://www.google.com/accounts/ServiceLoginAuth';
  $gmail_url = 'https://mail.google.com/';
  $cookie_file = dirname(__FILE__) . '/cookie.txt';
  
  $ch = curl_init();
  
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
  curl_setopt($ch, CURLOPT_URL, $login_url);
  $output = curl_exec($ch);
  echo $output;
  
  curl_setopt($ch, CURLOPT_URL, $gmail_url);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
  $output = curl_exec($ch);
  echo $output;
  
  curl_close($ch);
  </code></pre>