Voting

: zero minus zero?
(Example: nine)

The Note You're Voting On

phil at networkalliance dot com
17 years ago
I created a simple function that can be called to create global distribution groups in Active Directory:

<?php
function ldap_createGroup($object_name, $dn, $members, $ldap_conn)
{
$addgroup_ad['cn']="$object_name";
$addgroup_ad['objectClass'][0] = "top";
$addgroup_ad['objectClass'][1] ="group";
$addgroup_ad['groupType']="2";
$addgroup_ad['member']=$members;
$addgroup_ad["sAMAccountName"] =$object_name;

ldap_add($ldap_conn,$dn,$addgroup_ad);

if(
ldap_error($ldap_conn) == "Success")
return
true;
else
return
false;
}
?>

You can call this function using the follow code:

<?php
$ldap_conn
= ldap_bind();
$object_name="Test Group";
$dn="CN=".$object_name.",OU=PathToAddGroupTo,OU=All Users,DC=YOURDOMAIN,DC=COM";
$members[] ="CN=User1,OU=PathToAddGroupTo,OU=All Users,DC=YOURDOMAIN,DC=COM";
$members[] ="CN=User2,OU=PathToAddGroupTo,OU=All Users,DC=YOURDOMAIN,DC=COM";

ldap_createGroup($object_name, $dn, $members, $ldap_conn);
?>

The other function I created is ldap_bind(), and this can be used to bind to an LDAP server:

<?php
function ldap_bind()
{
$ldap_addr = '192.168.1.1'; // Change this to the IP address of the LDAP server
$ldap_conn = ldap_connect($ldap_addr) or die("Couldn't connect!");
ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldap_rdn = "domain_name\\user_account";
$ldap_pass = "user_password";

// Authenticate the user against the domain controller
$flag_ldap = ldap_bind($ldap_conn,$ldap_rdn,$ldap_pass);
return
$ldap_conn;
}
?>

<< Back to user notes page

To Top