Ldap Authentication

Here is a realy simple way to authenticate a user in PHP against Microsoft Active Directory.

function ldap_auth($username, $password){
    // connect to LDAP server
    if($username!=""){
        $ldap = ldap_connect("000.000.000.000") or die("Cannot connect to the ldap server :/");

        if (!($res = @ldap_bind($ldap,$username,$password)))
        {
            //print(ldap_error($ldap) . "<br>");
            return "";
        }
        else
        {
            return $username;
        }
    }
}

Just change "000.000.000.000" with the IP address of your AD server. DONE

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License