LDAP-Series-1-Chapter-3 - PHP-LDAP
来源:互联网 发布:mac散热声音大 编辑:程序博客网 时间:2024/06/01 14:13
If you want to use 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.soYou can change the path as you like.
$ php -vCheck if any error exist. (Until now, my work place`s php cannot load ldap.so)
PHP Test file.
<?phpclass m_ldap{ private $ldapHost = "127.0.0.1"; private $ldapPort = 389; private $ds; function m_ldap_con(){ $this->ds = ldap_connect($this->ldapHost,$this->ldapPort) or die("Could not 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 not 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 will be an error about PROTOCOL.
<?php require_once("m_ldap.php"); $mdap=new m_ldap(); $mdap->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 will works now. (Need ACL support, introduce next chapter.)
- LDAP-Series-1-Chapter-3 - PHP-LDAP
- LDAP-Series-1-Chapter-1
- LDAP-Series-1-Chapter-2
- LDAP-Series-1-Chapter-4 - ACL file
- php+ldap
- LDAP
- LDAP
- LDAP
- LDAP
- ldap
- LDAP
- LDAP
- LDAP
- LDAP
- LDAP
- LDAP
- LDAP
- ldap
- simulink与python进行数据交互
- 状态模式(State)
- 笔试面试题一
- HDU 4355 - Party All the Time
- MP3编码分析
- LDAP-Series-1-Chapter-3 - PHP-LDAP
- Selenium CSS
- hdoj 1010 Tempter of the Bone
- Lync 客户端无法及时更新!
- 策略模式(Strategy)
- OllyDbg调试iTools
- 周立功对人才的看法 读后很有感触
- hdoj 1076
- crontab使用说明及例子程序