Using Adldap2

Robert Andresen Uncategorized 6 Comments

I have been using Adldap v4.x at my work for a while now. After installing a test-server with PHP7, I found that the Adldap needed to be updated. I started with Adldap 5.x, but in the middle of the testing, it looked like the Adldap-project wasn’t maintained anymore. So I had to jump over to Adldap2, which wasn’t as straight forward from using Adldap v4.

Adldap2 has some great technical documentation of the basic structure and simple usage, but at this moment you have to dive into the source-code to use the most basic operations with your AD. I have collected some snippets here, for the most common needs.

 

Get user

 

Create user

 

Update user

Check “Create user”. Set attributes the same way. You can also wrap a if-statement around $user-save() to check if the user is saved or not.

 

Disable user

 

Enable user

 

Change user password

 

 

Get group members

There is a function to get member names in Adldap2, but as I use usernames as the uniq key, and not CN, I needed to fetch this info and build my own array.

 

Add user to group

To remove member, change: $result = $group->addMember($user);   to   $result = $group->removeMember($user);

 

 

I will try to update this article along the way…