Skip to content

Instantly share code, notes, and snippets.

@remoharsono
Last active October 18, 2019 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remoharsono/6a4753a0d80a2dc0af2dc9cb86f04755 to your computer and use it in GitHub Desktop.
Save remoharsono/6a4753a0d80a2dc0af2dc9cb86f04755 to your computer and use it in GitHub Desktop.
PHP: Login to LDAP
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