title: Logging In To Joomla 1.5 Using External Form (not within joomla folder, but on same server)
body: <p>I currently have a Joomla 1.5 installation, as well as another website.  They both reside on the same web server.  They are in different folders within the wwwroot directory, however.  I would like to place a login form within the non-joomla website, which will log the user in to Joomla.  I have already tried copying and pasting the Joomla login form code into a page on the non-joomla site, and everything works fine up until the secret form value is not correct.  Any help is greatly appreciated.</p>
  
  <p>EDIT:
  Here is the code-</p>
  
  <p>Contact form:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form id="login" name="login" method="post" action="login.php"&gt;
    &lt;label&gt;
    &lt;input name="username" type="text" id="username" value="username" /&gt;
    &lt;/label&gt;
      &lt;label&gt;
      &lt;input name="password" type="password" id="password" value="password" /&gt;
      &lt;/label&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;label&gt;
      &lt;input type="submit" name="submit" id="submit" value="Submit" /&gt;
      &lt;/label&gt;
    &lt;/p&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Login Script:</p>
  
  <pre><code>&lt;?php
  $uname = $_POST['username'];
  $upswd = $_POST['password'];
  $url = "http://www.mywebsite.com/joomla_site/index.php";
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url );
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
  curl_setopt($ch, CURLOPT_COOKIEJAR, './cookie.txt');
  curl_setopt($ch, CURLOPT_COOKIEFILE, './cookie.txt');
  curl_setopt($ch, CURLOPT_HEADER, FALSE );
  $ret = curl_exec($ch);
  if (!preg_match('/name="([a-zA-z0-9]{32})"/', $ret, $spoof)) {
      preg_match("/name='([a-zA-z0-9]{32})'/", $ret, $spoof);
  }
  
  // POST fields
  $postfields = array();
  $postfields['username'] = urlencode($uname);
  $postfields['passwd'] = urlencode($upswd);
  $postfields['lang'] = '';
  $postfields['option'] = 'com_login';
  $postfields['task'] = 'login';
  $postfields[$spoof[1]] = '1';
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  $ret = curl_exec($ch);
  ?&gt;
  </code></pre>