LDAP Authentication PHP

Prior to LDAP Implementation let us know few things first..

What is LDAP?

The Lightweight Directory Access Protocol (LDAP) is an application protocol for accessing and maintaining distributed directory information services over an Internet Protocol (IP) network.A common usage of LDAP is to provide a “single sign-on” where one password for a user is shared between many services, such as applying a company login code to web pages (so that staff log in only once to company computers, and then are automatically logged into the company intranet).

How it works?

A client starts an LDAP session by connecting to an LDAP server, called a Directory System Agent (DSA), by default on TCP port and UDP [5] port 389. The client then sends an operation request to the server, and the server sends responses in return.


An LDAP URL format exists, which clients support in varying degrees, and servers return in referrals and continuation references :


Check ldap dll file in extension folder of php and make sure it is activated.. remove semi colon in front of extension=php_ldap.dll

and restart the server once.

How to test LDAP ??


// using ldap bind
$ldaprdn = ‘username’; // ldap rdn or dn
$ldappass = ‘pwd’; // associated password
$ldaprdn1 = $ldaprdn.”@domain.com”;
// connect to ldap server
$ldapconn = ldap_connect(“domain.com”)
or die(“Could not connect to LDAP server.”);

if ($ldapconn) {

// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn1, $ldappass);

// verify binding
if ($ldapbind) {
echo “LDAP bind successful…”;
} else {
echo “LDAP bind failed…”;




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s