3.4 Accessing LDAP Directories from PHP

LDAP (Lightweight Directory Access Protocol) is used to access directory servers. Directory is a special kind of database that holds information in form of a tree structure. PHP for NetWare can access an LDAP directory through an LDAP extension.

The LDAP extension is enabled by default. If you want to disable this extension, comment the following entry in the sys:\php5\php.ini file.

 extension=PHP_LDAP.NLM
 

3.4.1 Accessing LDAP over SSL

To establish an SSL based function with the server, use ldap_connect functions with hostname as ’ldaps://’. A value of 636 for the port also establishes an SSL connection.

LDAP extension on NetWare reads the server certificates from a specific directory and uses them for SSL communication. sys:/php5/cert directory is the default directory to store server certificates.

All certificates available in this directory, at the time of loading the extension, are considered for SSL operations. To use a different directory, modify the ldap.ssl_cert_dir directive under the LDAP section in the php.ini file.

Example :

ldap_connect with hostname as ldaps

 <?php// make sure you have the certificate for the host you are trying to connect // in your server
 
 $ldaphost = "ldaps://ldap.example.com/";// Connecting to LDAP$ldapconn = ldap_connect($ldaphost)          or die("Could not connect to {$ldaphost}");?> 
 

Example:

ldap_connect with a value of 636 for port number argument

 <?php// make sure you have the certificate for the host you are trying to connect // in your server$ldaphost = "ldap.example.com";$port=636;// Connecting to LDAP$ldapconn = ldap_connect($ldaphost, $port)          or die("Could not connect to {$ldaphost}");?>
 

3.4.2 Changing eDirectory User Password

A new function is available to change the password of an eDirectory™ user.

bool ldap_change_password(resource link_identifier, string dn, string newpassword, [string oldpassword])

  • link_identifier

    Refers to the LDAP handle obtained from ldap_connect.

  • dn

    Refers to the distinguished name of the object.

  • newpassword

    The new password of the user.

  • oldpassword

    Refers to the password which has to be changed. This parameter is optional if you have logged in as ADMIN user.

This function returns TRUE if the change was successful else a warning message is displayed.

IMPORTANT:This feature cannot be used to clear passwords and is specific to NetWare® eDirectory™.

Example:

 $cr=ldap_change_password($ldapconn,"cn=MyName,o=MyOrg", "new_password", "old_password");