title: PHP CURL - Session expired
body: <p>I'm trying to make an voip call with PHP CURL and MEGAVOIP.
  The problem is i can't manage the session to access the page protected by a password.
  I looked which variables are posted to the login page to post it with Curl.
  But my code doesn't work.</p>
  
  <p>Following  Colin Morelli  and Waygood's advices, I just added those lines in both commands:</p>
  
  <pre><code>curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies_file);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies_file);
  </code></pre>
  
  <p>but it's still the same:</p>
  
  <p>Megavoip returns: SESSION EXPIRED</p>
  
  <p>So here is my full code:</p>
  
  <pre><code>&lt;?php
  ini_set("display_errors", 1);  
  $username="***"; 
  $password="***"; 
  $url="https://www.megavoip.com/login"; 
  $url2="https://www.megavoip.com/phone_to_phone/";
  $timeout = 10;
  $cookies_file = 'cookies.txt';
  
  // HERE I GET THE TOKEN
  
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies_file);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies_file);
  curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
  $content = curl_exec($ch);
  
  
  preg_match_all('/&lt;input[^&gt;]+&gt;/i',$content, $result); 
  preg_match_all('/(id|value)=("[^"]*")/i',$result[0][5], $img);
  $img1=str_replace('"', '', $img[0][0]);
  $img2=str_replace('"', '', $img[0][1]);
  $img1=substr($img1,3);
  $img2=substr($img1,6);
  $postdata = "login%5Busername%5D=".$username."&amp;login%5Bpassword%5D=".$password."&amp;page_referrer=login&amp;".$img1."=".$img2; 
  
  // HERE I SEND THE VARIABLES
  
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies_file);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies_file);
  curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  
  $content = curl_exec($ch);
  
  // IF LOGGED HERE I'LL MAKE THE CALL
  
  curl_close($ch);
  
  echo $content;
  exit;
  ?&gt;
  </code></pre>
  
  <p>Any ideas to help me?</p>
  
  <p>This is a test account so feel free to use my login and password if you want to have a look on this and help me!</p>
  
  <p>Thank you a lot in advance.</p>