1.代码实现
<?php
$user = $_POST ['name'];
$password = $_POST ['pwd'];
 
//设定域信息
$domain = 'a.com'; //设定域名
$basedn = 'dc=a,dc=com'; //如果域名为“b.a.com”,则此处为“dc=b,dc=a,dc=com”
 
$ad = ldap_connect ( "ldap://{$domain}" ) or die ( 'Could not connect to LDAP server.' );
ldap_set_option ( $ad, LDAP_OPT_PROTOCOL_VERSION, 3 );
ldap_set_option ( $ad, LDAP_OPT_REFERRALS, 0 );
@ldap_bind ( $ad, "{$user}@{$domain}", $password ) or die ( 'Authorization failed! Please check your username or password!' );
echo "Welcome ".$user;
?>
2. 一些有用的网站
adLDAP - LDAP Authentication with PHP for Active Directory
PHP: LDAP Functions – Manual http://php.net/manual/en/ref.ldap.php