Home Backend Development PHP Tutorial PHP operation AD, adLDAP class API detailed explanation and examples_PHP tutorial

PHP operation AD, adLDAP class API detailed explanation and examples_PHP tutorial

Jul 13, 2016 pm 05:45 PM
api php download and Example tool operate kind Detailed explanation pass

This article briefly describes how to operate AD through PHP
Tools ADLDAP.php
Download location http://adldap.sourceforge.net/download.php
API (the following is from http://adldap.sourceforge.net, the translation level is limited, please correct me if there are any inaccuracies)
constructor($options=array())//Constructor
You can specify the AD settings in the class through configuration variables, or they can be overridden by specifying the $option array when the class is called.
The calling method looks like $object = new adLDAP($options); $options is an array consisting of one or more of the following keys

account_suffix
Default: "@mydomain.local"
Full domain account suffix
base_dn
Default: “DC=mydomain,DC=local”
The base dn of the domain. Generally speaking, the base dn is the same as the account suffix, but is separated and prefixed with "DC=". The base dn can be located in the Active Directory Users and Computers MMC extensions
Exhibition attributes
If the authenticated user is normal but cannot search, it is generally because an incorrect base_dn
is specified.
domain_controllers
Default: array (“dc01.mydomain.local”)
Array of domain controllers. If you want this class to balance queries through multiple controllers, you can specify multiple controllers in this array. Remember that this class will send requests to an unreachable domain controller because it only implements Balance
No fault tolerance
.

ad_username
Default: NULL
By default, adLDAP will perform queries with the permissions of an authenticated user account. You can specify a user account with higher permissions to perform authorization operations

ad_password
Default: NULL
The corresponding password for ad_username.

real_primarygroup
Override primary group via "Domain Users"

use_ssl
Default: false
adLDAP can use LDAP through SSL to provide additional functions such as changing passwords. When selecting this option, both your domain controller and WEB server need to configure the corresponding options. Not only set it to true, please refer to the SSL method
for details. LDAP options

recursive_groups
Default: true
Recursive query group members
For example, user Fred is a member of the group "Business Unit", "Business Unit" is a member of the group "Department", and "Department" is a member of the group "Company"
user_ingroup("Fred","Company") returns true when the item is turned on, otherwise returns false
--------------------------The following main operation methods
authenticate($username,$password,$prevent_rebind=false)
Username/password to identify domain controller users

group_add_group($parent,$child)
Add a subgroup to the parent group, return true or false

group_add_user($group,$username)
Add a user to a group, return true or false

group_create($attributes)
Create a group with specified attributes, return true or false

Attribute Req Notes
group_name *
container *
description

group_del_group($parent,$child)
Delete the child group from the parent group, return true or false

group_del_user($group,$users)
Remove a user from a group, return true or false

group_info($group_name,$fields=NULL)
Returns an array of information about the specified group. Group names are case-sensitive
The default file contains member, memberof, description, distinguishedname, objectcategory, samaccountname

user_create($attributes)
Create a user, return true or false when the operation succeeds or fails

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 If it is 0, the user does not need to change the password when logging in next time. If it is 1, the password must be changed when logging in next time
company Company name.
department
description
display_name
email email address, non-exchange mailbox
enabled 0 means disabled 1 means enabled
expires Account validity period (unix timestamp).
firstname
home_directory
home_drive
initials
logon_name The login name is different from other usernames.
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)
Delete a user, return true or false

user_groups($username,$recursive=NULL)
Return the information of the group to which the user belongs

If $recursive is true, the group list will be returned recursively.

user_info($username,$fields=NULL)
Returns the information array of the specified user. $fields must be an array
The default fields are: samaccountname, mail, memberof, department, displayname, telephonenumber, primarygroupid
To view all available information, set $fields to "*" and call this function
This function will return a limited set. Unless the current authentication account is administrator, a user cannot query the "memberof" field of another user unless they are the administrator of this container

user_ingroup($username,$group,$recursive=NULL)
Whether the user belongs to the group, returns true or false
Like the user_info() function, this function will only return valid results when the current authenticated user is administrator

user_modify($username,$attributes)
Modify user attributes and return true or false

user_password($username,$password)
Set the password of the specified user. Requires configuration through ldaps.

computer_info($computer_name,$fields=NULL)
Returns detailed information for the specified computer.

all_users($include_desc = false, $search = "*", $sorted = true)
Returns the list of all users in AD, which may not work in large directories
all_groups($include_desc = false,$search = "*", $sorted = true)
Returns the list of all groups in AD, which may not work in large directories
Samples:
Login
include "adLDAP.php"
$config['account_suffix'] = '@xxx.com';//Domain controller suffix
$config['adserver'] = array('192.168.1.10','192.168.1.1');//Domain controller, if there is only one array('192.168.1.10')
$config['base_dn'] = 'cn=users,dc=xxx,dc=com';
$adldap =new adLDAP(array('domain_controllers'=>$config['adserver'],'account_suffix'=>$config['account_suffix'],'base_dn'=>$config
['base_dn'],'ad_username' => 'administrator','ad_password' => ''));
if($adldap)
{
echo "Login successful";
}
else
{
echo "Login failed";
}
?>
List all users
echo "All users
";
foreach($adldap->all_users() as $val)
{
echo $val."
";
}
?>
List all groups
echo "groups
";
foreach($adldap->all_groups() as $val)
{
echo $val."
";
}
?>
Print information about a certain computer
print_r($adldap->user_info("wang"));
?>
Create user
if ($adldap->user_create(array('username' => 'tonix','firstname' => 'firstname','surname' => "surname",'email' => 'e@ 123.com','container' =>
'container')))
{
echo "OK";
}
else
{
echo "error";
}
?>
Create group
if ($adldap->group_create("group_name=test,container=www"))
{
echo "OK";
}
else
{
echo "error";
}
?>

Author "Flying Life"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478629.htmlTechArticleThis article briefly describes how to operate AD through PHP tool ADLDAP.php download location http://adldap.sourceforge.net/download .php API (the following is from http://adldap.sourceforge.net, the translation level is limited, if there is anything wrong...
Statement of this Website
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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Top 10 virtual currency trading apps Latest rankings of top 10 virtual currency trading platforms in 2025 Top 10 virtual currency trading apps Latest rankings of top 10 virtual currency trading platforms in 2025 Apr 28, 2025 pm 02:09 PM

The top ten virtual currency trading apps are: 1. OKX, 2. Binance, 3. gate.io, 4. Coinbase, 5. Kraken, 6. Huobi, 7. KuCoin, 8. Bitfinex, 9. Bitstamp, 10. Poloniex. Each platform has outstanding performance in trading products, user experience, security, etc., to meet the needs of different investors.

How much is Bitcoin worth How much is Bitcoin worth Apr 28, 2025 pm 07:42 PM

Bitcoin’s price ranges from $20,000 to $30,000. 1. Bitcoin’s price has fluctuated dramatically since 2009, reaching nearly $20,000 in 2017 and nearly $60,000 in 2021. 2. Prices are affected by factors such as market demand, supply, and macroeconomic environment. 3. Get real-time prices through exchanges, mobile apps and websites. 4. Bitcoin price is highly volatile, driven by market sentiment and external factors. 5. It has a certain relationship with traditional financial markets and is affected by global stock markets, the strength of the US dollar, etc. 6. The long-term trend is bullish, but risks need to be assessed with caution.

Ranking of the top ten trading platforms in the currency circle The latest ranking of the top ten digital currency exchanges Ranking of the top ten trading platforms in the currency circle The latest ranking of the top ten digital currency exchanges Apr 28, 2025 pm 01:09 PM

Ranking of the top ten trading platforms in the currency circle: 1. Binance, 2. OKX, 3. gate.io, 4. Huobi Global, 5. Coinbase, 6. Kraken, 7. Bitfinex, 8. KuCoin, 9. Bybit, 10. Bitstamp. These platforms stand out in the market for their advantages such as high transaction volume, diverse trading pairs, strong security measures, innovative products, user-friendly interface, rich trading options and global services.

The latest ranking of the top ten trading platforms in the currency circle. The top ten digital currency exchanges rankings in 2025 The latest ranking of the top ten trading platforms in the currency circle. The top ten digital currency exchanges rankings in 2025 Apr 28, 2025 pm 01:39 PM

The rankings of the top ten trading platforms in the cryptocurrency circle in 2025 are: 1. Binance, 2. OKX, 3. gate.io, 4. Huobi Global, 5. Coinbase, 6. Kraken, 7. Bitfinex, 8. KuCoin, 9. Bybit, 10. Bitstamp. These platforms stand out in the market for their security, transaction volume, user experience and innovation.

Recommended reliable digital currency trading platforms. Top 10 digital currency exchanges in the world. 2025 Recommended reliable digital currency trading platforms. Top 10 digital currency exchanges in the world. 2025 Apr 28, 2025 pm 04:30 PM

Recommended reliable digital currency trading platforms: 1. OKX, 2. Binance, 3. Coinbase, 4. Kraken, 5. Huobi, 6. KuCoin, 7. Bitfinex, 8. Gemini, 9. Bitstamp, 10. Poloniex, these platforms are known for their security, user experience and diverse functions, suitable for users at different levels of digital currency transactions

Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Apr 28, 2025 pm 07:51 PM

Sesame Open Door is a platform that focuses on cryptocurrency trading. Users can obtain portals through official websites or social media to ensure that the authenticity of SSL certificates and website content is verified during access.

Spot King Transformation Note: How to layout the next generation of on-chain ecosystem with Gate.io MeMebox 2.0? Spot King Transformation Note: How to layout the next generation of on-chain ecosystem with Gate.io MeMebox 2.0? Apr 28, 2025 pm 03:36 PM

Gate.io has achieved the transformation from spot trading to on-chain ecosystem through MeMebox 2.0. 1) Build a cross-chain infrastructure and support the interoperability of 12 main chains; 2) Create a DeFi application ecosystem and provide one-stop services; 3) Implement incentive mechanisms and reconstruct value allocation.

Top 10 cryptocurrency speculation app rankings in 2025 Top 10 cryptocurrency speculation software rankings Top 10 cryptocurrency speculation app rankings in 2025 Top 10 cryptocurrency speculation software rankings Apr 28, 2025 pm 04:39 PM

Top 10 cryptocurrency trading apps in 2025: 1. OKX, providing rich market data and analysis tools; 2. Binance, comprehensive market data and "Binance Academy"; 3. Gate.io, supporting "currency mining"; 4. Coinbase, user-friendly interface and "Coinbase Earn"; 5. Kraken, providing "dark pool trading"; 6. Huobi, supporting "contract trading"; 7. KuCoin, providing "invitation rewards"; 8. Bitfinex, etc.

See all articles