Created
November 16, 2015 03:26
-
-
Save Noxwizard/ba8c20b7cec9b56afc86 to your computer and use it in GitHub Desktop.
LDAP testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Server settings | |
$ldap_server = 'ip or hostname of ldap server'; | |
$ldap_port = 389; | |
$ldap_user = 'domain\ldap_username'; | |
$ldap_pass = 'ldap user password'; | |
$ldap_base_dn = 'OU=Accounting,DC=test,DC=net'; | |
$ldap_uid = 'sAMAccountName'; | |
// User login test | |
$user = 'bob'; | |
$ldap = ldap_connect('ldap://' . $ldap_server . ':' . $ldap_port); | |
if (!$ldap) | |
die('Connecting to LDAP server failed'); | |
@ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); | |
@ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); | |
if (!ldap_bind($ldap, $ldap_user, $ldap_pass)) | |
die('LDAP Bind failed'); | |
$search = ldap_search( | |
$ldap, | |
htmlspecialchars_decode($ldap_base_dn), | |
ldap_user_filter($user), | |
array($ldap_uid), | |
0, | |
1 | |
); | |
$result = ldap_get_entries($ldap, $search); | |
ldap_close($ldap); | |
echo 'Results:<br />'; | |
print_r($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment