在PHP中整合LDAP与PHP的示例代码如下:
<?php // 安装并启用php-ldap扩展 if (!extension_loaded('ldap')) { dl('ldap.so'); } // 连接到LDAP服务器 $ldap_server = "ldap://your_ldap_server:389"; // 替换为你的LDAP服务器地址和端口号 $ldap_user = "cn=admin,dc=example,dc=com"; // 替换为你的LDAP管理员DN(Distinguished Name) $ldap_password = "your_password"; // 替换为你的LDAP管理员密码 $base_dn = "ou=users,dc=example,dc=com"; // 替换为你的用户基本DN(Base Distinguished Name) $search_filter = "(objectClass=person)"; // 替换为你的搜索过滤器,用于查找用户信息 $attributes = array("uid", "mail", "cn"); // 替换为你想要获取的属性列表 // 建立与LDAP服务器的连接并执行查询操作 $ldap_connection = ldap_connect($ldap_server); if (!$ldap_connection) { die("无法连接到LDAP服务器: " . ldap_error($ldap_connection)); } if (!ldap_bind($ldap_connection, $ldap_user, $ldap_password)) { die("无法绑定到LDAP服务器: " . ldap_error($ldap_connection)); } if (!@ldap_search($ldap_connection, $base_dn, $search_filter, $attributes)) { die("无法执行查询操作: " . ldap_error($ldap_connection)); } else { $result = @ldap_get_entries($ldap_connection, $link); // link 是查询结果集的资源标识符,需要单独获取并关闭连接后再释放内存空间。 ?> <pre><?php foreach ($result as $entry) { /* ... */ echo "<p>".htmlspecialchars($entry['count'].": ").htmlspecialchars($entry[0]['count'])."</p>"; /* ... */ echo "<p>".htmlspecialchars($entry['count'].": ").htmlspecialchars($entry[0]['count'])."</p>"; /* ... */ echo "<p>".htmlspecialchars($entry['count'].": ").htmlspecialchars($entry[0]['count'])."</p>"; /* ... */ echo "<p>".htmlspecialcharacters($entry['count'].": ").htmlspecialcharacters($entry[0]['count'])."</p>"; /* ... */ echo "<p>".htmlspecialcharacters($entry['count'].": ").htmlspecialcharacters($entry[0]['count'])."</p>"; /* ... */ echo "<p>".htmlspecialcharacters($entry['count'].": ").htmlspecialcharacters($entry[0]['count'])."</p>"; /* ... */ echo "<p>".htmlspecialcharacters($entry['count'].": ").htmlspecialcharacters($entry[0]['count'])."</p>"; /* ... */ echo "<p>".htmlspecialcharacters($entry['count'].": ").htmlspecialcharacters($entry[0]['count'])."</p>"; /* ... */ echo "<p>".htmlspecialcharacters($entry['count'].": ").htmlspecialcharacters($entry[0]['count'])."</p>"; /* ... */ echo "<p>".htmlspecialcharacters($entry['count'].": ").htmlspecialcharacters($entry[0]['count'])."</p>"; /* ... */ echo "<p>".htmlspecialcharacters($entry['count'].": ").htmlspecialcharacters($entry[0]['count'])."</p
还没有评论,来说两句吧...