Last active
October 18, 2019 06:49
-
-
Save remoharsono/6a4753a0d80a2dc0af2dc9cb86f04755 to your computer and use it in GitHub Desktop.
PHP: Login to LDAP
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
define("LDAP_HOST", "ldap://mydomain.co.id:389"); | |
define("LDAP_VERSION", 3); | |
function authLDAP($ldap_username, $ldap_password) { | |
$ret = array(); | |
if ($ldap_connection = ldap_connect(LDAP_HOST)) { | |
ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, LDAP_VERSION); | |
if ($ldap_bind = @ldap_bind($ldap_connection, $ldap_username, $ldap_password)) { | |
$ret['result'] = 'OK'; | |
} else { | |
$ret['result'] = 'ERROR_LOGIN'; | |
} | |
} else { | |
$ret['result'] = 'ERROR_CONNECTION'; | |
} | |
return $ret; | |
} | |
$ldap_username = 'username@mydomain.co.id'; | |
$ldap_password = 'secret'; | |
$accessLDAP = authLDAP($ldap_username, $ldap_password); | |
echo $accessLDAP['result']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment