title: Storing the response of login using curl?
body: <p>I have logged in to a website using url,username and password using curl.The main question is that i want to get the response back and store it in php script that the site has been logged in or not ? </p>
  
  <p>Storing response i.e. logged in or login failed in the php script is the main question ? I have given the script below can u tell me what to add ?</p>
  
  <p>Thanks in advance</p>
  
  <pre><code>&lt;?php
  
  $cookiefile = tempnam("/tmp", "cookies");
  
  $login_url='**********';
  
  
  $login_post_url='*********';
  
  
  $username = "*****";
  $password = "*****";
  
  $agent="Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2 ";
  
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$login_url);
  curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  $result = curl_exec ($ch);
  
  
  curl_close ($ch);
  
  
  
  $postfields = array(
          'j_username' =&gt; $username,
          'j_password' =&gt; $password,
      );
  
  $reffer = $login_url;
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$login_post_url);
  curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS,
         http_build_query($postfields));
  
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  
  curl_setopt($ch, CURLOPT_REFERER, $reffer);
  
  
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
  
  
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  
  $result = curl_exec ($ch);
   echo $result;
  
  curl_close ($ch);
  
  
  unlink($cookiefile);
  ?&gt;
  </code></pre>