Skip to content

Instantly share code, notes, and snippets.

@khapota
Created August 25, 2014 16:34
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 khapota/0a0f5c625e7e40cc9d81 to your computer and use it in GitHub Desktop.
Save khapota/0a0f5c625e7e40cc9d81 to your computer and use it in GitHub Desktop.
PHP LDAP Authentication sample
<?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