LDAP and PHP connection failure

后端 未结 7 851
予麋鹿
予麋鹿 2020-12-15 21:25

I am trying to connect to a secure LDAP server (using LDAPs) via PHP, but I am having problems with it. I get the following error

Warning: ldap_bind()

7条回答
  •  醉梦人生
    2020-12-15 21:32

    What saved my day after reading and trying out solutions from allover the web and SO, was to use a ldaps uri without the port specified in it.

    So instead of this: ldaps://example.com:636 I had to use this: ldaps://example.com and it now works like a charm.

    I was setting this up on Ubuntu 16.04 with PHP7.3 runing through Nginx and php-fpm.

    A full code example:

    try{
        $ldapUri = "ldaps://example.com";
        $ldapUsername = 'username';
        $ldapPassword = 'password';
        $ldapConn = ldap_connect($ldapUri);
        if($ldapConn){
            ldap_set_option($ldapConn,LDAP_OPT_NETWORK_TIMEOUT,10);
    
            if(!ldap_set_option($ldapConn,LDAP_OPT_PROTOCOL_VERSION,3)){
               print 'Failed to set ldap protocol to version 3
    '; } ldap_set_option($ldapConn, LDAP_OPT_REFERRALS,0); $ldapBind = ldap_bind($ldapConn, $ldapUsername, $ldapPass); if ($ldapBind) { echo "LDAP bind successful..."; //DO LDAP search and stuff ldap_unbind($ldapConn); } else { echo "LDAP bind failed..."; } } }catch(Exception $e){ print($e->getMessage(); }

提交回复
热议问题