PHP 通过 ldap_connect来连接域控,我这里使用的Win 2008 R2 Server创建的域控。(其实只要有ldap服务的机子都行,比如大名鼎鼎的OpenLDAP)
通过ldap_bind来判断用户名密码是否正确,
简易代码如下:
1 $ds=ldap_connect("172.16.80.233","389"); // must be a valid LDAP server! 2 $username='Administrator@zb.com'; 3 $username='123456'; 4 if ($ds) { 5 if($bind = ldap_bind($ds, $username, $password)) 6 { 7 //登录成功 8 session_start(); 9 header("Location: index.php"); //跳转到index.php页面 10 ldap_close($ds); 11 } 12 else 13 { 14 echo "登录失败"; 15 echo "<script type='text/javascript'>alert('帐号或密码错误');</script>"; 16 ldap_close($ds); 17 } 18 } 19 else 20 { 21 echo "无法连接Domain"; 22 }