I had problems connecting initially. But then I realised that the problem was actually just the "company name" that was wrong. You need to get that from the LDAP server administrator.
Details from the LDAP server administrator you need:
OU: Your company name Username: A username to test / connect to the LDAP server (ex. jannie) Password: A password for the above username (ex. password1) The LDAP Host ex: 10.0.0.1
<?php
define('LDAP_HOST','your ldap ip address'); define('LDAP_USER','your username'); define('LDAP_PASSWORD','your password');
$link = ldap_connect(LDAP_HOST,389) or die('could not connect'); $bind = ldap_bind($link,LDAP_USER,LDAP_PASSWORD) or die('could not bind');
$base_dn = "DC=your company name"; $filter = "(givenname=*)";
$result = ldap_search($link,$base_dn,$filter); $userDetails = ldap_get_entries($link,$result);
foreach($userDetails as $user){ foreach($user as $key=>$array){ if($key == "cn"){ $username = $array[0]; if($username != 'o'){ $users[] = $array[0]; } } } } $user = null; ldap_unbind($link);
echo "<pre>";print_r($users);echo "</pre>"; ?>
By PHPin24 @ 2009-07-07 13:22:40
|