title: HowTo login with PHP (and Curl) into DirectAdmin
body: <p>Hey guys, I am trying to create a script that will pull the log's from DirectAdmin so they can be parsed and submitted to a DB, the problem is the login of DirectAdmin.</p>
  
  <p>I tried lots of script but I cant seem to get it to work...</p>
  
  <p>Current script:</p>
  
  <pre><code>$url = 'http://213.247.000.000:2222/CMD_SHOW_LOG?domain=mydomain.com&amp;type=log';
  $username = 'xxx';
  $password = 'xxx';
      $fields = array(
          'username'=&gt;urlencode($username),
          'password'=&gt;urlencode($password)
          );
      $fields_string='';
      foreach($fields as $key=&gt;$value) { 
          $fields_string .= $key.'='.$value.'&amp;'; 
      }
      rtrim($fields_string,'&amp;');
      $ch = curl_init();
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch,CURLOPT_POST,count($fields));
      curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
      $result = curl_exec($ch);
      if($result===false) {
          echo 'CURL ERROR: '.curl_error($ch);
      }
      curl_close($ch);
  
      var_dump($result);
  </code></pre>