先开启php.ini中ext中的php_ldap.dll扩展。
PHP:
<?php $username = $_POST ['username']."@xxx"; $password = $_POST ['password']; $conn = ldap_connect('xxx.local') or die('无法连接AD服务器'); if ($conn) { $bind = ldap_bind($conn,$username, $password); if ($bind) { echo "验证通过"; } else { echo "验证失败"; } } ?>
ThinkPHP:
public function doLogin(){ $username = "companydomain\\".$_POST['username']; $password = $_POST['password']; $conn = ldap_connect('192.168.1.4') or die('无法连接AD服务器');; if ($conn) { $bind = ldap_bind($conn,$username, $password); // 如果连接了,便进行登入 if ($bind) { $this->success("验证通过",U('/admin/index/index')); } else { $this->error('登录失败'); } ldap_close($conn); }
其它
PHP手册:LDAP操作手册,
http://www.savh.cn/thread-291.htm
转载请注明:Savh.Cn 发表