Ldap-series-1-chapter-3-Php-ldap
If you want the PHP with LDAP. You have to add the extension lib. (ldap.so)
Go to the install file of PHP.
$ cd/opt/php-5.4.5/ext/ldap/$/usr/local/bin/phpize$./configure--with-php-config=/usr/local/bin/php-config-- with-ldap=/usr/local/openldap$ make$ make install$ cd/usr/local/lib$ vi php.ini (extension-dir=/usr/local/lib Extension=php_ldap.so) $ cp/usr/local/lib/php/ext/..../ldap.so/usr/local/lib/php_ldap.so
You can change the path as a.
$ php-v
Check if any error exist. (
Until Now, my work place ' s PHP cannot load ldap.so)
PHP Test file.
ds = Ldap_connect ($this->ldaphost, $this->ldapport) or Die ("Could does connect to $this->ldaphost"); return true; } function M_ldap_bind ($DN, $PSW) {ldap_set_option ($this->ds, ldap_opt_protocol_version, 3); if ($this->ds) {$r = Ldap_bind ($this->ds, $DN, $PSW) or Die ("Could is bind to $dn"); if ($r) {return true; }else{return false; }}else{return false; }} function M_ldap_add ($DN, $info) {$r =ldap_add ($this->ds, $dn, $info); if ($r) {return true; }else{return false; }} function M_ldap_modify ($DN, $info) {$r =ldap_modify ($this->ds, $dn, $info); if ($r){return true; }else{return false; }} function M_ldap_search ($DN, $filter) {$ldapSearch = Ldap_search ($this->ds, $dn, $filter); $ldapInfo = Ldap_get_entries ($this->ds, $ldapSearch); return $ldapInfo; }}?>
Ldap_set_option ($this->ds, ldap_opt_protocol_version, 3); Make the DS to use PROTOCOL VERSION 3, Otherwise, there'll be a error about PROTOCOL.
M_ldap_con (); $DN = "cn=root,ou=systemadmin,dc=xxx,dc=org"; $PSW = "xxxxxx"; $mdap->m_ldap_bind ($DN, $PSW) or Die ("Cannot bind"); $SDN = "ou=people,ou=iweb,dc=weiwejia,dc=org"; $filter = "(uid=*)"; $res = $mdap->m_ldap_search ($sdn, $filter); foreach ($res [0]["cn"] as $key = = $val) { print $key. " \ n "; Print $val. " \ n "; }?" >
If everything has been OK, it'll works now. (Need ACL support, introduce next chapter.)