您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP操作AD,adLDAP类API详解与实例_PHP教程

2025/8/12 22:40:44发布35次查看
本文简述通过php操作ad
工具 adldap.php
下载位置http://adldap.sourceforge.net/download.php
api(以下来自http://adldap.sourceforge.net,翻译水平有限,如有不妥之处敬请指正)
constructor($options=array())//构造器
你可以通过配置变量的方式指定该类中ad的设置, 或者当类被调用的时候可以通过指定$option数组的方式被覆盖.
调用方式形似 $object = new adldap($options); $options 是一个由下列一个或多个keys组成的数组
account_suffix
默认:”@mydomain.local”
完整的域帐户后缀
base_dn
默认: “dc=mydomain,dc=local”
域的base dn. 一般来讲 base dn 与account suffix相同, 但是被隔开的且以dc=为前缀. base dn 可被定位于active directory users及computers mmc的扩
展属性上
如果认证用户正常,但不能搜索,一般来说是由于指定了不正确的base_dn
domain_controllers
默认: array (“dc01.mydomain.local”)
域控制器数组,如果你希望该类通过多个控制器来平衡查询,可以在该数组中指定多个控制器,记住该类会向一个不可连接的域控制器发送请求,因为它只实施平衡
而无容错
.
ad_username
默认: null
默认地,adldap会以已经认证的用户帐号权限执行查询,你可以指定一个拥有更高权限的用来执行授权操作的用户帐号
ad_password
默认: null
ad_username相应的密码.
real_primarygroup
通过“domain users” 覆盖 primary group
use_ssl
默认: false
adldap 可以通过ssl使用ldap以提供额外功能例如修改密码,选择此项时你的域控制器和web服务器均需配置相应选项,不只将其设置为true,详细请参考ssl方式的
ldap选项
recursive_groups
默认: true
递归查询组成员
如用户fred是组“business unit” 的成员,“business unit” 是组department”的成员,department”是组“company”的成员
user_ingroup(“fred”,”company”)当该项开启的时候返回true,否则返回false
------------------------以下主要的操作方法
authenticate($username,$password,$prevent_rebind=false)
鉴别域控制器用户的username/password
group_add_group($parent,$child)
向父组里添加子组,返回true或false
group_add_user($group,$username)
向一个组里添加一个用户,返回true或false
group_create($attributes)
以指定属性创建一个组,返回true或false
attribute req notes
group_name *  
container *  
description  
group_del_group($parent,$child)
从父组里删除子组,返回true或false
group_del_user($group,$users)
从一个组里删除一个用户,返回true或false
group_info($group_name,$fields=null)
返回一个关于指定组的信息数组,组名称区分大小写
默认文件包含member, memberof, description, distinguishedname, objectcategory, samaccountname
user_create($attributes)
创建一个用户,操作成功或失败时返回true或false
attribute req notes
username *  
firstname *  
surname *  
email *  
container * the folder in ad to add the user to.
address_city   
address_code   
address_pobox   
address_state   
address_street   
change_password   如果为0用户下次登录时无需修改密码为1时下次登录时必须修改密码
company   公司名称.
department   
description   
display_name   
email   email地址,非exchange mailbox
enabled   0 为 disabled 1 为 enabled   
expires   帐户有效期 (unix timestamp).
firstname   
home_directory   
home_drive   
initials   
logon_name   登录名称不同于其他用户名.
manager   
office   
password   the password can only be set over ssl. it must also meet the password policy for your domain.
profile_path   
script_path   
surname   
title   
telephone   
web_page  
user_delete($username)
删除一个用户,返回 true 或 false
user_groups($username,$recursive=null)
返回用户所属组的信息
如果$recursive为 true, 将递归返回组列表.
user_info($username,$fields=null)
返回指定用户的信息数组,$fields必须为数组
默认fields 为: samaccountname, mail, memberof, department, displayname, telephonenumber, primarygroupid
欲查看所有可用信息,将$fields 设置*调用此函数
这个函数将返回一个有限集,除非当前认证帐户为administrator,一个用户也不能查询另一个用户的memberof域,除非它们是这个容器的管理者
user_ingroup($username,$group,$recursive=null)
用户是否属于该组,返回true或false
像user_info()函数一样,这个函数只有当当前认证用户是administrator时才会返回有效结果
user_modify($username,$attributes)
修改用户属性,返回true或false
user_password($username,$password)
设置指定用户的密码,. 要求配置通过ldaps.
computer_info($computer_name,$fields=null)
返回指定计算机的详细信息.
all_users($include_desc = false, $search = *, $sorted = true)
返回ad里用户所有列表,在大目录里可能无法工作
all_groups($include_desc = false,$search = *, $sorted = true)
返回ad里组所有列表,在大目录里可能无法工作
samples:
登录
$config['adserver'],'account_suffix'=>$config['account_suffix'],'base_dn'=>$config
['base_dn'],'ad_username' => 'administrator','ad_password' => ''));
if($adldap)
{
    echo 登录成功;
}
else
{
    echo 登录失败;
}
?>
列出所有用户
all_users() as $val)
{
echo $val.
;
}
?>
列出所有组
all_groups() as $val)
{
echo $val.
;
}
?>
打印某台计算机信息
user_info(wang));
?>
创建用户
user_create(array('username' => 'tonix','firstname' => 'firstname','surname' => surname,'email' => 'e@123.com','container' =>
'container')))
{
echo ok;
}
else
{
echo error;
}
?>
创建组
group_create(group_name=test,container=www))
{
echo ok;
}
else
{
echo error;
}
?>
作者“飞翔的人生”
http://www.bkjia.com/phpjc/478629.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/478629.htmltecharticle本文简述通过php操作ad 工具 adldap.php 下载位置http://adldap.sourceforge.net/download.php api(以下来自http://adldap.sourceforge.net,翻译水平有限,如有不妥之...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product