Follow the instructions in our manual to add our package repository and then run the below command.
apt-get install halon-extras-ldap
yum install halon-extras-ldap
These classes needs to be imported from the extras://ldap
module path.
The LDAP class is a OpenLDAP wrapper class.
Params
- uri
string
- The URI should be in the format ofldap://
orldaps://
. Multiple hosts may be given separated by space.
Returns: class object
$ldap = LDAP("ldap://ldap.forumsys.com");
$ldap->bind("uid=tesla,dc=example,dc=com", "password");
$x = $ldap->search("dc=example,dc=com");
while ($x and $entry = $x->next())
echo $entry;
Set LDAP connection options. On error none
is returned.
Params
- name
string
- the option name - value
any
- the option value
Returns: this
Return type: LDAP
or none
if (!$ldap->setoption("network_timeout", 5))
echo LDAP::err2string($ldap->errno());
The following options are available
Name | Type | Default | Description |
---|---|---|---|
protocol_version | number | 3 |
|
referrals | boolean | false |
|
network_timeout | number | 0 |
No timeout |
timeout | number | 0 |
No timeout (in seconds) |
timelimit | number | 0 |
No timelimit (in seconds) |
tls_verify_peer | boolean | true |
Verify peer certificate |
tls_default_ca | boolean | false |
Load additional TLS certificates (ca_root_nss) |
Get LDAP connection options. On error none
is returned.
Params
- name
string
- the option name
Returns: result
Return type: any
or none
The following options are available
Name | Type | Description |
---|---|---|
diagnostic_message | string | Gets the latest session error message |
Issue STARTTLS on LDAP connection. On error none
is returned.
Returns: this
Return type: LDAP
or none
Bind the LDAP connection. For anonymous bind, do not specify the credentials. On error none
is returned.
Params
- dn
string
- The username DN - cred
string
- The password credentials
Returns: this
Return type: LDAP
or none
Search LDAP connection in the current base and subtree. On error none
is returned.
Params
- basedn
string
- Base DN - options
array
- an options array
The following options are available in the options array.
- scope
string
- The search scope, available scopes aresub
(subtree),one
(onelevel) andbase
. The default issub
. - filter
string
- The search filter. The default is(objectclass=*)
. - attributes
array
- Array of attributes to fetch. The default is to fetch all.
Returns: A LDAP result class
Return type: LDAPResult
or none
Unbind the LDAP connection. On error none
is returned.
Returns: this
Return type: LDAP
or none
Get the latest errno returned from the underlying OpenLDAP API.
Returns: errno
Return type: number
Get the peer certificate (X.509) as a X509
instance. On error none
is returned.
Returns: The peer certificate
Return type: X509
or none
Get a descriptive error message, uses OpenLDAP’s ldap_err2string()
.
Params
- errno
number
- A errno (obtained from LDAP’s errno())
Returns: An error string
Return type: string
if (!$ldap->bind())
echo LDAP::err2string($ldap->errno());
LDAP escape values to be used in LDAP filters.
Params
- value
string
- An unescaped string
Returns: An escaped string
Return type: string
$result = $ldap->search("dc=example,dc=com", ["filter" => "(cn=" . LDAP::filter_escape($cn) . ")"]);
Parses the string representation of a distinguished name str into its components, returning an array of tupels. On error none
is returned.
Params
- str
string
- String representation of a DN
Returns: Array of tupels
Return type: array
or none
echo LDAP::str2dn("cn=admin,dc=example,dc=org");
// [0=>[0=>"cn",1=>"admin"],1=>[0=>"dc",1=>"example"],2=>[0=>"dc",1=>"org"]]
Performs the inverse operation of str2dn()
, returning a string representation of dn with the necessary escaping. On error none
is returned.
Params
- dn
array
- Array of tupels
Returns: String representation of the DN
Return type: string
or none
A LDAP result iterable object which holds the result from an LDAP search.
Return the next result. If there are no more results false
is returned, and on error none
is returned.
Returns: entry data
Return type: array
or none
$result = $ldap->search("dc=example,dc=com");
if ($result)
while ($entry = $result->next())
echo $entry;