48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
|
<?php
|
||
|
// LDAPS server details
|
||
|
$ldapServer = 'ldaps://your-ldap-server.com';
|
||
|
$ldapPort = 636;
|
||
|
|
||
|
// LDAP bind credentials
|
||
|
$ldapUsername = 'your-ldap-username'; // Usually in the form of username@domain.com
|
||
|
$ldapPassword = 'your-ldap-password';
|
||
|
|
||
|
// Connect to LDAPS server
|
||
|
$ldapConn = ldap_connect($ldapServer, $ldapPort);
|
||
|
|
||
|
// Check for successful connection
|
||
|
if (!$ldapConn) {
|
||
|
die("Could not connect to LDAP server");
|
||
|
}
|
||
|
|
||
|
// Disable SSL/TLS certificate verification
|
||
|
ldap_set_option($ldapConn, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
|
||
|
|
||
|
// Set LDAP options
|
||
|
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||
|
ldap_set_option($ldapConn, LDAP_OPT_REFERRALS, 0);
|
||
|
|
||
|
// Bind to LDAP server
|
||
|
$ldapBind = ldap_bind($ldapConn, $ldapUsername, $ldapPassword);
|
||
|
|
||
|
// Check for successful bind
|
||
|
if (!$ldapBind) {
|
||
|
die("LDAP bind failed");
|
||
|
}
|
||
|
|
||
|
// Now you can perform LDAP operations, such as searching or modifying data
|
||
|
|
||
|
// For example, searching for a user
|
||
|
$searchDN = 'ou=Users,dc=example,dc=com'; // Adjust the base DN as per your AD structure
|
||
|
$searchFilter = '(sAMAccountName=username)'; // Adjust the filter for your needs
|
||
|
|
||
|
$searchResult = ldap_search($ldapConn, $searchDN, $searchFilter);
|
||
|
$entries = ldap_get_entries($ldapConn, $searchResult);
|
||
|
|
||
|
// Display the results
|
||
|
print_r($entries);
|
||
|
|
||
|
// Don't forget to close the connection when done
|
||
|
ldap_close($ldapConn);
|
||
|
?>
|