0

I've been looking at a couple of guides (and the PHP manual) trying to validate AD users on an intranet site I'm about to make. This is the first time I've used ldap_connect, and I haven't had the best of luck.

Could anyone look at my code and see what I'm missing?

Thanks.

<?php
    $user = "08jf1";
    $password = "pass";

    // Active Directory server
    $ldap_host = "10.43.48.5"; 

    // Active Directory DN
    $ldap_dn = "OU=CSE-W7,OU=Students-W7,DC=server,DC=local";

    // Domain, for purposes of constructing $user
    $ldap_usr_domain = "@server.local";

    // Connect to AD host
    $ldapconn = ldap_connect("10.43.48.5");

    if ($ldapconn) { 
            $bind = ldap_bind($ldap_host, $ldap_dn, $user . $ldap_usr_domain, $password);

            if ($bind) {
                echo "Verified user";

                //$_SESSION['username'] = $session_username;
                //$_SESSION['password'] = $session_password;

                } else {
                    echo "User does not exist";
                }
        }
?>

Edit: I can confirm ldap is enabled though phpinfo!

Josh J
  • 78
  • 1
  • 6

3 Answers3

2

Is that syntax of ldap_bind correct?. Isn't it ldap_bind($ldapconn,$rdn,$password) ?

Terry Gardner
  • 10,957
  • 2
  • 28
  • 38
0

Binding may need a elevated privilege or authbind wrapper. Refer to authbind for ldap. LDAP AuthBind

Kris
  • 8,680
  • 4
  • 39
  • 67
0

Take a look at this very simple example: How to use LDAP Active Directory Authentication with PHP

Joe Meyer
  • 4,315
  • 20
  • 28