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).
Try specifying the port in the URL - it's not the standard port 389. So 'ldap://hostname:3268'?
Unless you are using LDAP with SSL , you are not required to specify ldap://
in 1st parameter of ldap_connect()
function.
Therefore, ldap_connect('hostname')
is correct.
Note: For LDAP with SSL , you can use ldap_connect('ldaps://hostname')
.
Reference: http://php.net/manual/en/function.ldap-connect.php