Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP LDAP connection using URL

Tags:

php

ldap

I have a problem while trying to connect from an Ubuntu server with PHP5 to a LDAP server using URL('ldap://hostname/'). The code works fine when I'm not using the URL format ($server = 'hostname').

The code:

$server = 'ldap://hostname/';

$ldapconn = ldap_connect($server, 3268) or die("Could not connect to LDAP server.");

if ($ldapconn) {
    $ldapbind = @ldap_bind($ldapconn, 'username', 'password');
    $error_ldap_code =  ldap_errno($ldapconn) ;
    if($error_ldap_code==0) {
        echo 'Connected!!!';
    }
}

Edit:

I needed ldaps, but I saw that with ldap I have the same problem. While the problem related to ldap was solved by adding the port in the URL, I still had the ldaps issue. Anyway, I managed to bypass it by using ldap_start_tls ( resource $link ) after connecting using only the hostname (without URL format).

like image 463
Mihai Avatar asked Jun 12 '26 14:06

Mihai


1 Answers

Try specifying the port in the URL - it's not the standard port 389. So 'ldap://hostname:3268'?

like image 177
nikkumang Avatar answered Jun 14 '26 07:06

nikkumang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!