title: How to add a new user in OpenLDAP via PHP?
body: <p>I want to add a new user in OpenLDAP and I write the following method to create a new user. When calling this method, I have to pass the following variables:</p>
  
  <ul>
  <li><code>$ldapconn</code> : Returned by ldap_connect.</li>
  <li><code>$username</code> : The username that I want to create.</li>
  <li><code>$password</code> : The password for logging in the account.</li>
  </ul>
  
  <hr>
  
  <pre><code>public static function createNewUser($ldapconn, $username, $password) {
      if (!$ldapconn) { return false; }
      require_once("LDAPConfigurator.php");
      $r = ldap_bind($ldapconn, "cn=admin,dc=test,dc=com", "12345X");
  
      // Prepare data
      $info["cn"]="John Jones";
      $info["sn"]="Jones";
      $info["mail"]="jonj@example.com";
      $info["objectclass"]="person";
  
      // Add data to directory
      $r = ldap_add($ldapconn, "cn=John Jones,dc=test,dc=com", $info);
  
      return true;
  }
  </code></pre>
  
  <p>The LDAP connection <code>$ldapconn</code> will be closed outside this method.</p>
  
  <hr>
  
  <p>The prepared data is copied from <a href="http://titanic.fauser.edu/php/function.ldap-add.php.htm" rel="nofollow">this document</a>.</p>
  
  <p>I expect it can show me a new child under "dc=test,dc=com" in phpLDAPadmin. But the final result is nothing appeared and shows me:</p>
  
  <pre><code>Warning: ldap_add(): Add: Object class violation in /var/www/html/test.php on line 23
  </code></pre>
  
  <p>I want to ask how to solve the problem (<code>Object class violation</code>)?</p>