Prev | Current Page 497 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

To do so, you use the ldap_bind() function. Its prototype follows:
boolean ldap_bind(resource link_id [, string rdn [, string pswd]])
Although anybody could feasibly connect to the LDAP server, proper credentials
are often required before data can be retrieved or manipulated. This feat is accomplished
using ldap_bind(). This function requires at minimum the link_id returned
from ldap_connect() and likely a username and password denoted by rdn and pswd,
respectively. An example follows:
$host = "ldap.openldap.org";
$port = "389";
$connection = ldap_connect($host, $port)
or die("Can't establish LDAP connection");
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_bind($connection, $username, $pswd)
or die("Can't bind to the server.");
?>
Note that the credentials supplied to ldap_bind() are created and managed within
the LDAP server and have nothing to do with any accounts residing on the server or
the workstation from which you are connecting. Therefore, if you are unable to connect
anonymously to the LDAP server, you need to talk to the system administrator to
arrange for an appropriate account.
Also, demonstrated in the previous example, to connect to the test ldap.openldap.org
server you??™ll need to execute ldap_set_option() because only the version 3 protocol
is accepted.
Closing the LDAP Server Connection
After you have completed all of your interaction with the LDAP server, you should
clean up after yourself and properly close the connection.


Pages:
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509