Skip to content

Instantly share code, notes, and snippets.

@csiebear
Last active October 4, 2021 11:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save csiebear/ce0980529b6d7a0f80f8b8cd32311fff to your computer and use it in GitHub Desktop.
Save csiebear/ce0980529b6d7a0f80f8b8cd32311fff to your computer and use it in GitHub Desktop.
Test php ldap function
//domain name(or URL),account,password should replace with actual string
<?php
//For testing the AD server is work or not
$ldaphost="domain name";
$ldapconn=ldap_connect($ldaphost);
if($ldapconn)
echo "Connect success<br>";
else
echo "Connect Failure";
//For simplification,you can wirte $ldapconn = ldap_connect($ldaphost)or die("Could not connect to ".$ldaphost);
//rdn:relative distinguished name
$User="account";
$ldaprdn=$User."@".$ldaphost;
$ldappass="password";
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
//Reference:http://php.net/manual/en/function.ldap-bind.php
if ($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
echo "LDAP bind successful...";
} else {
echo "LDAP bind failed...";
}
}
ldap_close($ldapconn);
?>
@Vitsen15
Copy link

Vitsen15 commented Oct 4, 2021

ldap_connect never returns bool value.

Please see the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment