note 36367 added to ref.ldap
| From: | pookey at pookey dot co dot uk | Date: | Tue, 07 Oct 2003 17:57:23 +0000 |
| Subject: | note 36367 added to ref.ldap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57970@lists.php.net to get a copy of this message | ||
This is an example of how to query an LDAP server, and print all entries out.
<?php
$ldapServer = '127.0.0.1';
$ldapBase = 'DC=anlx,DC=net';
/*
* try to connect to the server
*/
$ldapConn = ldap_connect($ldapServer);
if (!$ldapConn)
{
die('Cannot Connect to LDAP server');
}
/*
* bind anonymously
*/
$ldapBind = ldap_bind($ldapConn);
if (!$ldapBind)
{
die('Cannot Bind to LDAP server');
}
/*
* set the ldap options
*/
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
/*
* search the LDAP server
*/
$ldapSearch = ldap_search($ldapConn, $ldapBase, "(cn=*)");
$ldapResults = ldap_get_entries($ldapConn, $ldapSearch);
for ($item = 0; $item < $ldapResults['count']; $item++)
{
for ($attribute = 0; $attribute < $ldapResults[$item]['count']; $attribute++)
{
$data = $ldapResults[$item][$attribute];
echo
$data.": ".$ldapResults[$item][$data][0]."<br>";
}
echo '<hr />';
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.ldap.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36367
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36367&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36367&report=yes
Search -- http://master.php.net/manage/user-notes.php