Listing C: ldap_error function
<?php
// LDAP variables
$ldap[‘user’]              = ‘uname’;
$ldap[‘pass’]              = ‘password’;
$ldap[‘host’]              = ‘ldap.example.com’;
$ldap[‘port’]              = 389;
$ldap[‘dn’]          = ‘cn’.$ldap[‘user’].’,ou=Department,o=Company Name’;
$ldap[‘base’]              = ‘’;
 
// connecting to ldap
$ldap[‘conn’] = ldap_connect( $ldap[‘host’], $ldap[‘port’] )
or die( “Could not connect to server {$ldap[‘host’]} );
 
// binding to ldap
$ldap[‘bind’] = ldap_bind( $ldap[‘conn’], $ldap[‘dn’], $ldap[‘pass’] );
 
if( !$ldap[‘bind’] )
{
    echo ldap_error( $ldap[‘conn’] );
    exit;
}
 
?>