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
LDAP 目錄協議函數庫http://etdep.yxnu.net/php_manu/group.php-25.htm
Apache Module mod_auth_ldap http://httpd.apache.org/docs/2.0/mod/mod_auth_ldap.html
LDAP Authentication (PHP) http://code.activestate.com/recipes/101525-ldap-authentication/
LDAP精華文章 http://www.chinaunix.net/jh/49/