title: PHP, cURL post to login to WordPress
body: <p>I am working on a project for a client which needs an automatic login from a link click.</p>
  
  <p>I'm using a handshake page to do this with the following code:</p>
  
  <pre><code>$username = "admin";
  $password = "blog";
  $url = "http://wordpressblogURL/";
  $cookie = "cookie.txt";
  
  $postdata = "log=" . $username . "&amp;pwd=" . $password . "&amp;wp-submit=Log%20In&amp;redirect_to=" . $url . "blog/wordpress/wp-admin/&amp;testcookie=1";
  $ch = curl_init();
  curl_setopt ($ch, CURLOPT_URL, $url . "blog/wordpress/wp-login.php");
  
  curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
  curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
  curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0);
  curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
  curl_setopt ($ch, CURLOPT_REFERER, $url . "blog/wordpress/wp-login.php");
  
  curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
  curl_setopt ($ch, CURLOPT_POST, 1);
  $result = curl_exec ($ch);
  curl_close($ch);
  echo $result;
  
  exit;
  </code></pre>
  
  <p>This works fine. It logs me in great.</p>
  
  <p>The problem is that I believe WordPress keys off of the URL.</p>
  
  <p>To elaborate, my handshake page (which logs me in) is in the "blog" directory and my WordPress application is in the "wordpress" directory which sits inside the "blog" directory. The URL in the browser says <code>..blog/handshake.php</code>. However, it has the Admin section of WordPress in the browser window. WordPress Admin links now do not function correctly, because the URL is in the <code>../blog</code> directory when it needs to be in the <code>..blog/wordpress/wp-admin</code> directory.</p>
  
  <p>Is there a way in <a href="http://en.wikipedia.org/wiki/CURL" rel="noreferrer">cURL</a> to make it so that the URL in the browser reflects the actual page?</p>
  
  <p>Should I be using FSockOPen instead?</p>