LDAPPHP
Adldap2 là gói PHP cung cấp các công cụ quản lý thư mục và xác thực LDAP bằng cách sử dụng mẫu Bản ghi Hoạt động Show · Tài liệu
Lỗ hổng bảo mậtNếu bạn phát hiện ra lỗ hổng bảo mật trong Adldap2, vui lòng gửi e-mail tới Steve Bauman qua steven_bauman@outlook. com FreeDSx LDAP là một thư viện PHP LDAP thuần túy. Nó không có yêu cầu về phần mở rộng LDAP PHP cốt lõi. Thư viện này hiện triển khai hầu hết chức năng máy khách được mô tả trong RFC 4511 và một số chức năng máy chủ LDAP rất hạn chế. Nó cũng triển khai một số tính năng máy khách khác từ các RFC khác nhau
Nó hỗ trợ mã hóa kết nối LDAP thông qua TLS thông qua tiện ích mở rộng OpenSSL nếu có Tài liệu
Cài đặt qua nhà soạn nhạc composer require freedsx/ldap Sử dụng lớp LdapClient và các lớp trợ giúp use FreeDSx\Ldap\LdapClient; use FreeDSx\Ldap\Operations; use FreeDSx\Ldap\Search\Filters; $ldap = new LdapClient([ # Servers are tried in order until one connects 'servers' => ['dc1', 'dc2'], # The base_dn is used as the default for searches 'base_dn' => 'dc=example,dc=local' ]); # Encrypt the connection prior to binding $ldap->startTls(); # Bind to LDAP with a specific user. $ldap->bind('[email protected]', '12345'); # Build up a LDAP filter using the helper methods $filter = Filters::and( Filters::equal('objectClass', 'user'), Filters::startsWith('cn', 'S'), # Add a filter object based off a raw string filter... Filters::raw('(telephoneNumber=*)') ); # Create a search operation to be used based on the above filter $search = Operations::search($filter, 'cn'); # Create a paged search, 100 results at a time $paging = $ldap->paging($search, 100); while ($paging->hasEntries()) { $entries = $paging->getEntries(); var_dump(count($entries)); foreach ($entries as $entry) { echo "Entry: ".$entry->getDn().PHP_EOL; } }Hoạt động CRUD Tạo rause FreeDSx\Ldap\Entry\Entry; use FreeDSx\Ldap\Exception\OperationException; # Create a new LDAP entry object $entry = (new Entry('cn=foo,dc=domain,dc=local')) ->set('objectClass','top', 'group') ->set('sAMAccountName', 'foo'); # Create the entry with the LDAP client try { $ldap->create($entry); } catch (OperationException $e) { echo sprintf('Error adding entry (%s): %s', $e->getCode(), $e->getMessage()).PHP_EOL; } Đọc# Use the read() method of the LDAP client to search for a specific entry. # Optionally pass an array of attributes to select as the second argument. $entry = $ldap->read('cn=foo,dc=domain,dc=local'); # Entry will be null if it doesn't exist if ($entry) { echo $entry.PHP_EOL; var_dump($entry->toArray()); } Cập nhậtuse FreeDSx\Ldap\Exception\OperationException; # Search for an entry object to get its current attributes / values $entry = $ldap->read('cn=foo,dc=domain,dc=local'); # Add a value to an attribute if (!$entry->get('telephoneNumber')) { $entry->add('telephoneNumber', '555-5555'); } # Remove any values an attribute may have if ($entry->has('title')) { $entry->reset('title'); } # Delete a specific value for an attribute if ($entry->get('ipPhone')->has('12345')) { $entry->delete('ipPhone', '12345'); } # Set a value for an attribute. This replaces any value it may, or may not, have. $entry->set('description', 'Employee'); # Send the built up changes back to LDAP to update the entry via the LDAP client update method. try { $ldap->update($entry); } catch (OperationException $e) { echo sprintf('Error modifying entry (%s): %s', $e->getCode(), $e->getMessage()).PHP_EOL;; } Xóa bỏuse FreeDSx\Ldap\Exception\OperationException; # Search for the entry object to delete $entry = $ldap->read('cn=foo,dc=domain,dc=local'); # Pass the entry object to the delete method of the LDAP client if it was found. # You could also pass a DN object or a simple DN as a string. if ($entry) { try { $ldap->delete($entry); } catch (OperationException $e) { echo sprintf('Error deleting entry (%s): %s', $e->getCode(), $e->getMessage()).PHP_EOL;; } } LDAP trong PHP là gì?LDAP là Giao thức truy cập thư mục nhẹ và là một giao thức được sử dụng để truy cập "Máy chủ thư mục". Thư mục là một loại cơ sở dữ liệu đặc biệt chứa thông tin trong cấu trúc cây.
Làm cách nào để bật LDAP trong PHP?Cài đặt ¶
. Bạn sẽ cần phải sử dụng tùy chọn cấu hình --with-ldap[=DIR] khi biên dịch PHP để kích hoạt hỗ trợ LDAP . DIR là thư mục cài đặt cơ sở LDAP. Để bật hỗ trợ SASL, hãy đảm bảo --with-ldap-sasl[=DIR] được sử dụng và sasl đó.
Làm cách nào để kiểm tra xem PHP có hỗ trợ LDAP không?Bạn có thể thử và kiểm tra bằng extension_loaded() như thế này. $buildWithLdap = extension_loaded('ldap'); hoặc cách tiếp cận xà beng khác, chỉ cần kiểm tra xem một trong các chức năng có tồn tại hay không. $buildWithLdap = function_exists('ldap_add');
Làm cách nào để bật LDAP trong PHP trên Ubuntu?Tìm kiếm ExtensionList trong php. tệp ini. Bỏ chú thích extension=php_ldap. dll, nếu không có thì thêm dòng này vào tệp và lưu tệp . |