What is LDAP? How PHP operates LDAP

Source: Internet
Author: User
Tags array count ldap mail connect
how PHP operates LDAP
2.1 How PHP connects and shuts down with LDAP
$ds =ldap_connect ("ServerName")
ServerName is the name of the LDAP server,

Cases:
$ds =ldap_connect ("10.31.172.30:1000")
The return value is: TRUE or False

Close connection
Ldap_close ($DS);

2.2 How to search for user information in PHP

$ds =ldap_connect ("10.31.172.30:1000");
Connect to the server first
$justthese = Array ("CN", "UserPassword", "location");
Search for a parameter in a function that asks what information to return.
The above is returned to cn,userpassword,location, which requires lowercase
$SR =ldap_search ($ds, "O=jite", "cn=dom*", $justthese);
The first parameter opens the LDAP code
The second parameter most basic DN condition value, Example: "O=JITE,C=CN"
The third parameter, filter, is a Boolean condition, and its syntax can be found on a dirsdkpg.pdf file at Netscape station.
' O ' for organization name, ' CN ' for username, user name available wildcard ' * '
echo "DomAdmin surname has". Ldap_count_entries ($ds, $SR). "<p>";
Ldap_count_entries ($ds, $SR) returns the total number of records

$info = Ldap_get_entries ($ds, $SR);
Full return of LDAP data
echo "Data returns". $info [Count]. " Pen:<p> ";
for ($i =0; $i < $info [Count]; $i + +) {
echo "DN is:". $info [$i] [dn]. " <br> ";
Echo "CN is:". $info [$i] ["cn"][0]. " <br> "; Display user Name
echo "Email is:". $info [$i] ["Mail"][0]. " <p> "; Show mail
echo "Email is:". $info [$i] ["UserPassword"][0]. " <p> "; Display the encrypted password
}
2.3 Adding users
$ds =ldap_connect ("10.31.172.30:1000");
Connect to the server first
$r =ldap_bind ($ds, "Cn=domadmin,o=jite", "password");
Fasten an admin, have write permission
Cn=domadmin,o=jite order cannot be changed
$info ["cn"]= "AAA"; Must fill
$info ["UserPassword"]= "AAA";
$info ["Location"]= "Shanghai";
$info ["objectclass"] = "person"; Must fill in person for personal, also have server ...
Ldap_add ($ds, "cn=". $info ["cn"]. ", O=jite", $info);
Ldap_unbind ($DS);
Unbind
Ldap_close ($DS);
Close connection
2.4 Delete User
$ds =ldap_connect ("10.31.172.30:1000");
Connect to the server first
Ldap_bind ($ds, "Cn=domadmin,o=jite", "password");
Binding administrator, with permission to delete
$DN = "Cn=dingxf,o=jite";
Ldap_delete ($ds, $DN);
Delete User
Ldap_unbind ($DS);
Unbind
Ldap_close ($DS);
Close connection
2.5 Modify User Information
$ds =ldap_connect ("10.31.172.30:1000");
Connect to the server first
Ldap_bind ($ds, "Cn=domadmin,o=jite", "password");
Binding administrator, with modified permissions
$DN = "Cn=dingxf,o=jite";
User DN
$info ["UserPassword"]= "AAA"; The information to be modified, placed in the array variable
$info ["Location"]= "SHANGHAISDAF";

Ldap_modify ($ds, $DN, $info);
modifying functions
Ldap_unbind ($DS);
Unbind
Ldap_close ($DS);
Close connection
2.6 User logon authentication
$ds =ldap_connect ("10.31.172.30:1000");
Connect to the server first
if (Ldap_bind ($ds, "Cn=dingxf,o=jite", "DINGXF")) {
echo "Validate through";
}else{
echo "Validation does not pass";
}
Ldap_unbind ($DS);
Unbind
Ldap_close ($DS);
Close connection



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.