note 81113 added to function.ldap-add

From: Date: Thu, 14 Feb 2008 17:24:38 +0000
Subject: note 81113 added to function.ldap-add
Groups: php.notes 
Request: Send a blank email to php-notes+get-136147@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 65.123.200.2 ---- Manual Page -- http://www.php.net/manual/en/function.ldap-add.php Edit -- https://master.php.net/note/edit/81113 Del: integrated -- https://master.php.net/note/delete/81113/integrated Del: useless -- https://master.php.net/note/delete/81113/useless Del: bad code -- https://master.php.net/note/delete/81113/bad+code Del: spam -- https://master.php.net/note/delete/81113/spam Del: non-english -- https://master.php.net/note/delete/81113/non-english Del: in docs -- https://master.php.net/note/delete/81113/in+docs Del: other reasons-- https://master.php.net/note/delete/81113 Reject -- https://master.php.net/note/reject/81113 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136147) next »