title: cUrl login is not working
body: <p>I'm trying to login to one of my sites using curl to pull information off the page.  It does not seem to be working.  Here's the code I'm trying.  If it helps I can create a user/pass for just this scenario.</p>
  
  <pre><code>&lt;?php
  
  $username = 'xxx';
  $password = 'xxx';
  $loginUrl = 'http://gwintersdev.com/user';
  $finalUrl = 'http://gwintersdev.com/admin';
  
  $userinput = 'name';
  $passwordinput = 'pass';
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
  curl_setopt($ch, CURLOPT_URL,$loginUrl);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "$userinput=$username&amp;$passwordinput=$password");
  curl_setopt($ch, CURLOPT_USERAGENT, 'user-agent');
  
  
  ob_start();      // prevent any output
  curl_exec ($ch); // execute the curl command
  ob_end_clean();  // stop preventing output
  
  curl_close ($ch);
  unset($ch);
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
  curl_setopt($ch, CURLOPT_URL, $finalUrl);
  
  $buf2 = curl_exec ($ch);
  
  curl_close ($ch);
  print $buf2;
  ?&gt;        
  </code></pre>
  
  <p>Update: I was able to get the above working, but I'm trying this on a different ASP site and it's not working. I grabbed all the hidden fields and added them to the post string, but it still won't login.</p>
  
  <pre><code>&lt;?php
  $username = 'xxx';
  $password = 'xxx';
  $loginUrl = 'http://vitalstim.com/health_professionals/certified_provider_resources/forum.aspx';
  $finalUrl = 'http://vitalstim.com/health_professionals/certified_provider_resources/forum.aspx';
  $userinput = 'ctl00$ContentPlaceHolder1$uc_login$txtUser';
  $passwordinput = 'ctl00$ContentPlaceHolder1$uc_login$txtPass';
  $login = 'ctl00$ContentPlaceHolder1$uc_login$butLogin';
  
  $validation_input = '__EVENTVALIDATION';
  $validation_input_value = '/wEWAgKf+PTrBQKItpn5BDXHCHsANbEpwkEBmMyNv+32L2Ec';
  $view_state = '/wEPDwUJLTQyMjg0NzI0D2QWAmYPZBYGAgEPZBYEAgYPFgIeB1Zpc2libGVoZAIHDxYCHwBoZAIDD2QWBAIBD2QWCAIBD2QWBAIBDw8WAh4EVGV4dGVkZAIFDw8WAh8AaGRkAgcPZBYCAgEPZBYCAgMPZBYCAgEPFgIfAGhkAgkPDxYCHwBoZGQCCw8PFgIfAGhkZAIDDxYCHwBoZAIFDw8WAh8BBXY8c2NyaXB0IGxhbmd1YWdlPSJqYXZhc2NyaXB0IiB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPgokKGRvY3VtZW50KS5yZWFkeShmdW5jdGlvbigpIHsKVml0YWxTdGltLkluaXQoNCk7Cn0pOwo8L3NjcmlwdD4KZGRkdz/7+FcQ1E1sbC0Gua3jJsCGSnM=';
  $event_valid = '/wEWBwKeiM4xAoi2mfkEAurz/r4MAvTX0jYC+4GopQkCo6iimggC2pO41g77y84VwyhP6Ek+7PGZYDNgOawRZw==';
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
  curl_setopt($ch, CURLOPT_URL, $loginUrl);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS,   "$userinput=$username&amp;$passwordinput=$password&amp;$validation_input=$validation_input_value&amp;$login=login&amp;__EVENTVALIDATION=$event_valid&amp;_VIEWSTATE=$view_state");
  curl_setopt($ch, CURLOPT_USERAGENT, 'user-agent');
  curl_exec ($ch); // execute the curl command
  
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
  curl_setopt($ch, CURLOPT_URL, $finalUrl);
  
  $buf2 = curl_exec ($ch);
  curl_close ($ch);
  print $buf2;
  ?&gt;
  </code></pre>