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);
//关闭连接

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)