Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $ldap = array(
- 'url' => 'ETPRO.lokaal',
- 'domain' => 'ETPRO.lokaal';
- 'dn' => "dc=ETPRO,dc=lokaal"
- );
- $ds = ldap_connect( $ldap['url'] );
- ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
- ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
- $username = "Niels";
- //must always check that password length > 0
- $password = "Hoornbeeck12";
- // now try a real login
- $login = ldap_bind( $ds, sprintf( '%s@%s', $username, $ldap['domain'] ), $password );
- echo '- Logged In Successfully<br/><br/>';
- try{
- $attributes = array(
- "displayname",
- "mail",
- "department",
- "title",
- "physicaldeliveryofficename",
- "manager"
- );
- $filter = "(&(objectCategory=person)(sAMAccountName=$username))";
- $result = ldap_search($ds, $ldap['dn'], $filter, $attributes);
- $entries = ldap_get_entries($ds, $result);
- if($entries["count"] > 0){
- echo "<b>User Information:</b><br/>";
- echo "displayName: ".$entries[0]['displayname'][0]."<br/>";
- echo "email: ".$entries[0]['mail'][0]."<br/>";
- echo "department: ".$entries[0]['department'][0]."<br/>";
- echo "title: ".$entries[0]['title'][0]."<br/>";
- echo "office: ".$entries[0]['physicaldeliveryofficename'][0]."<br/>";
- $manager_result = ldap_search(
- $ds,
- $entries[0]['manager'][0],
- '(objectCategory=person)',
- $attributes
- );
- $manager_entries = ldap_get_entries($ds, $manager_result);
- if($manager_entries["count"] > 0){
- $values = ldap_get_values( $ds, $manager_entries[0], "cn" );
- printf( "Manager: %s", (string) array_pop( $values ) );
- }
- }
- }
- catch(Exception $e){
- echo $e;
- }
- ldap_unbind($ds);
- echo '<br/><br/>- Logged Out';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement