The easiest way to achieve this is normally via a JParameter
object. This means that we can use the JParameter and JElement classes to allow an
administrator to define the necessary LDAP settings:
$params = new JParameter($paramString);
$client = new JLDAP($params);
The next step is to connect to the LDAP server. This is relatively easy:
if (!$client->connect())
{
// connection failed, handle it!
}
APIs and Web Services
[ 292 ]
The connect() method instantiates a connection with the LDAP server. Once we are
connected we need to bind to the server. There are two ways of doing this.
We can bind anonymously; this is generally less common because of security issues
and privacy of data. To do this we use the anonymous_bind() method:
if (!$client->anonymous_bind())
{
// bind failed, handle it!
}
Alternatively, we can bind as a user. In this example, we bind as the user Manager
with the password secret, the default user and password in an OpenLDAP server:
if (!$client->bind('Manager', 'secret'))
{
// bind failed, handle it!
}
You might be scratching your head because of the username.
Pages:
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401