ldap-series-a-chapter-3-php-ldap

Source: Internet
Author: User
Tags ldap ldapsearch
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.)




  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.