note 36369 added to ref.domxml
| From: | pookey at pookey dot co dot uk | Date: | Tue, 07 Oct 2003 18:32:54 +0000 |
| Subject: | note 36369 added to ref.domxml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57972@lists.php.net to get a copy of this message | ||
LDAP to XML script! - http://www.pookey.co.uk
<?php
$ldapServer = '81.91.100.18';
$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);
header('Content-type: text/xml');
$xmlRoot = domxml_new_doc("1.0");
$xmlContacts = $xmlRoot->create_element('contacts');
$xmlRoot->append_child($xmlContacts);
for ($item = 0; $item < $ldapResults['count']; $item++)
{
$contact = $xmlRoot->create_element("contact");
for ($attribute = 0; $attribute < $ldapResults[$item]['count']; $attribute++)
{
$data = $ldapResults[$item][$attribute];
$xmlValues = $xmlRoot->create_element($data . 's');
for ($value = 0; $value < $ldapResults[$item][$data]['count']; $value++)
{
$xmlValue = $xmlRoot->create_element($data);
$xmlValueText = $xmlRoot->create_text_node($ldapResults[$item][$data][$value]);
$xmlValue->append_child($xmlValueText);
$xmlValues->append_child($xmlValue);
}
//echo
$data.": ".$ldapResults[$item][$data][0]."<br>";
$contact->append_child($xmlValues);
}
$contacts->append_child($contact);
}
echo $xmlRoot->dump_mem();
?>
----
Manual Page -- http://www.php.net/manual/en/ref.domxml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36369
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36369&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36369&report=yes
Search -- http://master.php.net/manage/user-notes.php