Created
August 25, 2014 16:34
-
-
Save khapota/0a0f5c625e7e40cc9d81 to your computer and use it in GitHub Desktop.
PHP LDAP Authentication sample
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 | |
// LDAP variables | |
$ldaphost = ""; // your ldap servers | |
$ldapport = 389; // your ldap server's port number | |
// Connecting to LDAP | |
$ldapconn = ldap_connect($ldaphost, $ldapport) | |
or die("Could not connect to $ldaphost"); | |
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); | |
if ($ldapconn) { | |
// binding to ldap server | |
$user = "username"; | |
$dn = "uid=$user, ou=people, dc=domain, dc=com"; | |
$pass = 'secretPassword'; | |
$ldapbind = @ldap_bind($ldapconn, $dn, $pass) | |
or die("Can not verify"); | |
// verify login | |
if ($ldapbind) { | |
echo "Login successful..."; | |
} else { | |
echo "Login failed..."; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment