title: phpbb3 curl login
body: <p>I'm trying to make an autologin bot for phpbb 3.0.10 with curl.
  The forum returns "You have been successfully logged in." but after that when i try to go to another page in the site and get the source with file_get_contents or even if i wait the page to redirect me to index.php it agains ask me to login.
  The point is that i'm doing these test on localhost and the forum is on another server and that's why i use curl..
  Here's my code:</p>
  
  <pre><code>&lt;?php
  $urltopost = "http://www.site.com/phpbb3eng/ucp.php?mode=login";
  $fget = file_get_contents($urltopost);
  $sid_a = explode('index.php?sid=',$fget);
  $sid_b = explode('"',$sid_a[1]);
  $sid = $sid_b[0];
  $datatopost = array (
  'username' =&gt; "bot",
  'password' =&gt; "123456789asd",
  'autologin' =&gt; "1",
  'viewonline' =&gt; "1",
  'redirect' =&gt; "./ucp.php?mode=login",
  'sid' =&gt; "$sid",
  'redirect' =&gt; "index.php?sid=$sid",
  'login' =&gt; "login"
  );
  
  $ch = curl_init ($urltopost."&amp;sid=$sid");
  curl_setopt ($ch, curlopt_post, true);
  curl_setopt ($ch, curlopt_postfields, $datatopost);
  curl_setopt ($ch, curlopt_returntransfer, true);
  curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (windows; u; windows nt 6.1; en-us; rv:1.9.1.2) gecko/20090729 firefox/3.5.2 gtb5');
  $returndata = curl_exec ($ch);
  $code = $returndata;
  echo htmlspecialchars($code); //returns source with successful login
  $code2 = file_get_contents("http://www.site.com/phpbb3eng/index.php"); 
  echo "&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;".htmlspecialchars($code2); // return login form
  ?&gt;
  </code></pre>