title: PHP CURL Authentication error code 302
body: <p>I need to send a post request with authentication.</p>
  
  <p>I try this code but I get error 302.</p>
  
  <pre><code>$url = "https://wifinext.internavigare.com/prepagataAnagrafica/creaUtente/";
  $username = 'myuser';
  $password = 'mypassword';
  // create a new cURL resource
  $ch= curl_init($url);
  
  // do a POST request, using application/x-www-form-urlencoded type
  curl_setopt($ch, CURLOPT_POST, TRUE);
  // credentials
  curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
  // returns the response instead of displaying it
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  
  //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  
  //Set Post Fields
  curl_setopt($ch, CURLOPT_POSTFIELDS, "Prepagata_codice=Test&amp;Prepagata_password=123456");
  
  // do request, the response text is available in $response
  $response = curl_exec($ch);
  // status code, for example, 200
  $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  
  //show response
  echo $statusCode;
  echo $response;
  
  // close cURL resource, and free up system resources
  curl_close($ch);
  </code></pre>
  
  <p>I see some answer say to use CURLOPT_FOLLOWLOCATION or cookies and I try it but I cannot figure out how to do. I'm about to pull out my hair. Please some help is really appreciated.</p>