search
Homephp教程php手册LDAP是什么?Php如何操作LDAP

Php如何操作LDAP
2.1 Php如何与LDAP连接和关闭
$ds=ldap_connect("ServerName")
ServerName是LDAP的服务器名,

例:
$ds=ldap_connect(“10.31.172.30:1000”)
返回值是:true 或 false

关闭连接
ldap_close($ds);

2.2 在php中如何搜索用户信息

$ds=ldap_connect("10.31.172.30:1000");
//首先连接上服务器
$justthese = array("cn","userpassword",”location”);
//搜索函数中的一个参数,要求返回哪些信息,
//以上传回cn,userpassword,location,这些都要求小写
$sr=ldap_search($ds,"o=jite", "cn=dom*",$justthese); 
//第一个参数开启LDAP的代号
//第二个参数最基本的 dn 条件值 , 例:”o=jite,c=cn”
//第三个参数 filter 为布林条件,它的语法可以在 Netscape 站上找一份 dirsdkpg.pdf 档案.
// ’o’为组织名,’cn’ 为用户名,用户名可用通配符 ’*’
echo "domadmin姓氏有".ldap_count_entries($ds,$sr)." 个

";
//ldap_count_entries($ds,$sr)传回记录总数

$info = ldap_get_entries($ds, $sr);
//LDAP的全部传回资料
echo "资料传回 ".$info["count"]."笔:

";
for ($i=0; $iecho "dn为:". $info[$i]["dn"] ."
";
echo "cn为:". $info[$i]["cn"][0] ."
"; //显示用户名
echo "email为:". $info[$i]["mail"][0] ."

"; //显示mail
echo "email为:". $info[$i][“userpassword"][0] ."

"; //显示加密后的密码
}
2.3 添加用户
$ds=ldap_connect("10.31.172.30:1000");
//首先连接上服务器
$r=ldap_bind($ds,"cn=domadmin,o=jite","password");
//系住一个管理员,有写的权限
// cn=domadmin,o=jite顺序不能变
$info["cn"]="aaa"; //必填 
$info["userpassword"]="aaa"; 
$info["location"]="shanghai";
$info["objectclass"] = "person"; //必填person为个人,还有server…
ldap_add($ds, "cn=".$info["cn"].",o=jite", $info);
ldap_unbind($ds);
//取消绑定
ldap_close($ds);
//关闭连接
2.4 删除用户
$ds=ldap_connect("10.31.172.30:1000");
//首先连接上服务器 
ldap_bind($ds,"cn=domadmin,o=jite","password");
//绑定管理员,有删除的权限
$dn="cn=dingxf,o=jite";
ldap_delete($ds, $dn);
//删除用户
ldap_unbind($ds);
//取消绑定
ldap_close($ds);
//关闭连接
2.5 修改用户资料
$ds=ldap_connect("10.31.172.30:1000");
//首先连接上服务器 
ldap_bind($ds,"cn=domadmin,o=jite","password");
//绑定管理员,有修改的权限
$dn="cn=dingxf,o=jite"; 
//用户dn
$info["userpassword"]="aaa"; //要修改的信息,放在数组变量中
$info["location"]="shanghaisdaf";

ldap_modify($ds, $dn , $info);
//修改函数
ldap_unbind($ds);
//取消绑定
ldap_close($ds);
//关闭连接
2.6 用户登录验证
$ds=ldap_connect("10.31.172.30:1000");
//首先连接上服务器 
if (ldap_bind($ds,"cn=dingxf,o=jite","dingxf")){
echo "验证通过";
}else{
echo "验证不通过";
}
ldap_unbind($ds);
//取消绑定
ldap_close($ds);
//关闭连接



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)