 |
|
ดึงข้อมูลของ USER จาก LDAP ตามโค๊ดนี้ค่ะ
Code (PHP)
<?php
$host = "192.168.0.1"; //ip server
$user = "[email protected]"; //username admin of server
$pswd = "12345"; //password server
$ad = ldap_connect($host) or die("Could not connect!");
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set ldap protocol");
$bd = ldap_bind($ad, $user, $pswd) or die ("Could not bind");
$dn = "DC=test,DC=com"; //มาตาม server คือ test.com หากมีมากกว่านี้ก็ใช้ DC เพิ่มเข้าไปอีก เช่น crop.test.com จะได้ "DC=crop,DC=test,DC=com"
$filter = "cn=*";
$search = ldap_search($ad, $dn, $filter) or die ("Search failed");
$entries = ldap_get_entries($ad, $search);
echo "<strong>FINE NUMBER : ".$entries["count"]." USER</strong><br><br>";
for ($i=0; $i<$entries["count"]; $i++) {
echo "dn is: ". $entries[$i]["dn"] ."<br>";
echo "first cn entry is: ". $entries[$i]["cn"][0] ."<br>";
echo "first email entry is: ". $entries[$i]["mail"][0] ."<br>";
echo "Title entry is: ". $entries[$i]["title"][0] ."<br>";
echo "Username is: ". $entries[$i]["samaccountname"][0] ."<br>";
echo "====================================================<br>";
}
?>
ผลที่ได้ มี 1000 คน ถ้าต้องการมากกว่า 1000 คน จะต้องแก้ยังไงค่ะ และถ้าต้องการเอาข้อมูลที่ดึงมาได้ INSERT ลงใน MySQL จะต้องทำยังไงค่ะ ขอบคุณค่ะ
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2012-08-01 15:16:31 |
By :
jittiporn.puk |
View :
3146 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |