日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php ldap 创建用户,PHP LDAP获取作为组成员的成员的用户详细信息

發布時間:2025/4/5 php 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php ldap 创建用户,PHP LDAP获取作为组成员的成员的用户详细信息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用

Sam J Levy創建的出色功能完成了它.

這是最終的代碼.

function explode_dn($dn, $with_attributes=0)

{

$result = ldap_explode_dn($dn, $with_attributes);

foreach($result as $key => $value) $result[$key] = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $value);

return $result;

}

function get_members($group,$user,$password) {

$ldap_host = "LDAPSERVER";

$ldap_dn = "OU=some_group,OU=some_group,DC=company,DC=com";

$base_dn = "DC=company,DC=com";

$ldap_usr_dom = "@company.com";

$ldap = ldap_connect($ldap_host);

ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION,3);

ldap_set_option($ldap, LDAP_OPT_REFERRALS,0);

ldap_bind($ldap, $user . $ldap_usr_dom, $password);

$results = ldap_search($ldap,$ldap_dn, "cn=" . $group);

$member_list = ldap_get_entries($ldap, $results);

$dirty = 0;

$group_member_details = array();

foreach($member_list[0]['member'] as $member) {

if($dirty == 0) {

$dirty = 1;

} else {

$member_dn = explode_dn($member);

$member_cn = str_replace("CN=","",$member_dn[0]);

$member_search = ldap_search($ldap, $base_dn, "(CN=" . $member_cn . ")");

$member_details = ldap_get_entries($ldap, $member_search);

$group_member_details[] = array($member_details[0]['givenname'][0],$member_details[0]['sn'][0],$member_details[0]['telephonenumber'][0],$member_details[0]['othertelephone'][0]);

}

}

ldap_close($ldap);

return $group_member_details;

}

// Specify the group from where to get members and a username and password with rights to query it

$result = get_members("groupname","username","password");

// The following will create an XML file with the details from $group_member_details

$xml = simplexml_load_string("<?xml version='1.0'?>\n");

$version = $xml->addChild('version', '1');

foreach($result as $e) {

$contact = $xml->addChild('Contact');

$contact->addChild('FirstName', $e[0]);

$contact->addChild('LastName', $e[1]);

$phone = $contact->addChild('Phone');

if ($e[3] == '') {

$phone->addChild('phonenumber', '0');

} else {

$phone->addChild('phonenumber', $e[3]);

}

$phone->addChild('accountindex', '0');

$phone = $contact->addChild('Phone');

if ($e[2] == '') {

$phone->addChild('phonenumber', '0');

} else {

$phone->addChild('phonenumber', $e[2]);

}

$phone->addChild('accountindex', '1');

$contact->addChild('Group', '0');

$contact->addChild('PhotoUrl', 'empty');

}

$xml->asXML('phonebook.xml');

?>

總結

以上是生活随笔為你收集整理的php ldap 创建用户,PHP LDAP获取作为组成员的成员的用户详细信息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。