snowal raj

snowal raj

  • NA
  • 166
  • 39.5k

How to add user in ldap in php

Mar 17 2017 6:25 AM
Hai,
 
       I nedd to add user in Ldap usign php
 
i try this
 
<?php
$AD_server = "192.168.1.55";
$ds = ldap_connect($AD_server);
if ($ds) {
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); // IMPORTANT
$result = ldap_bind($ds, "cn=admin,dc=sw,dc=com","jpqw$"); //BIND
if (!$result)
{
echo 'Not Binded';
}
 
 
 
$ldaprecord['objectclass'][0] = "inetorgperson";
$ldaprecord['objectclass'][1] = "posixaccount";
$ldaprecord['objectclass'][2] = "top";
$ldaprecord['cn'] = 'netbeans';
$ldaprecord['givenname'] = 'netbeans1';
$ldaprecord['sn'] = 'netbeans2';
$ldaprecord['mail'] = '[email protected]';
$ldaprecord['mobile'] = '+91 1234567890';
$ldaprecord['uid'] = 'nb';
$ldaprecord['displayname'] = 'netbeans';
$ldaprecord['uidnumber'] = '1005';
$ldaprecord['gidnumber'] = '501';
$ldaprecord['userpassword'] = "{crypt}123456";
$ldaprecord['gecos'] = 'netbeans';
$ldaprecord['loginshell'] = '/bin/sh';
$ldaprecord['homedirectory'] = '/home/users/nb';
$ldaprecord['shadowexpire'] = '-1';
$ldaprecord['shadowflag'] = '0';
$ldaprecord['shadowwarning'] = '7';
$ldaprecord['shadowmin'] = '8';
$ldaprecord['shadowmax'] = '999999';
$ldaprecord['shadowlastchange'] = '10877';
$ldaprecord['postalcode'] = '31000';
$ldaprecord['l'] = 'toulouse';
$ldaprecord['o'] = 'example';
$ldaprecord['homephone'] = '+33 (0)40 35963258';
$ldaprecord['title'] = 'system administrator';
$ldaprecord['postaladdress'] = '';
$ldaprecord['initials'] = 'jd';
// $ldaprecord["cn"] = "testuser";
// $ldaprecord["givenname"] = "Test";
// $ldaprecord["sn"] = "User";
// $ldaprecord["sAMAccountName"] = "testuser";
// $ldaprecord['userPrincipalName'] = "[email protected]";
// $ldaprecord["objectClass"] = "user";
// $ldaprecord["displayname"] = "Test User";
// $ldaprecord["userPassword"] = "Password01";
// $ldaprecord["userAccountControl"] = "544";
$base_dn = "cn=netbeans,cn=HR,ou=cbe,dc=sw,dc=com";
$r = ldap_add($ds, $base_dn, $ldaprecord);
if ($r)
{
echo 'Success';
}
else
{
echo ldap_errno($ds) ;
}
} else {
echo "cannot connect to LDAP server at $AD_server.";
}
?>
 
and Ig got Error NO 65
 
please help me