title: PHP cURL redirects to localhost
body: <p>I'm trying to login to an external webpage using a php script with cURL.  I'm new to cURL, so I feel like I'm missing a lot of pieces.  I found a few examples and modified them to allow access to https pages.  Ultimately, my goal is to be able to login to the page and download a .csv by following a specified link once logged in.  So far, what I have is a script that tests logging in to the page; the script is shown below:</p>
  
  <pre><code>$ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://www.websiteurl.com/login');
  curl_setopt($ch, CURLOPT_POSTFIELDS,'Email='.urlencode($login_email).'&amp;Password='.urlencode($login_pass).'&amp;submit=1');
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
  curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
  curl_setopt($ch, CURLOPT_REFERER, "https://www.websiteurl.com/login");
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  $output = curl_exec($ch);
  </code></pre>
  
  <p>I have a few questions.  First, is there a reason this does not redirect on its own?  The only way for me to view the contents of the page is to </p>
  
  <pre><code>echo $output
  </code></pre>
  
  <p>even though CURLOPT_RETURNTRANSFER and CURLOPT_FOLLOWLOCATION are both set to True.</p>
  
  <p>Second, the URL for the page stays at "localhost/folderName/test.php" instead of directing to the actual website.  Can anyone explain why this happens?  Because the script doesn't actually redirect to a logged in webpage, I can't seem to do anything that I need to do. </p>
  
  <p>Does my issue have to do with cookies?  My cookies.txt file is in the same folder that my .php script is.  (I'm using wampServer btw).  Should it be located elsewhere? </p>
  
  <p>Once I'm able to fix these two issues, it seems that all I need to be able to do is to redirect to the link that start the download process for the .csv file.</p>
  
  <p>Thanks for any help, much appreciated!</p>