大菜鸟在云端 发表于 2012-10-23 22:40:54

PHP与LDAP登录相关 ( Win 2008 R2 Server Domain Controller )

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'; 4if ($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    else13     {14    echo "登录失败";15    echo "<script type='text/javascript'>alert('帐号或密码错误');</script>";     16     ldap_close($ds);17     }18   }19else 20   { 21  echo "无法连接Domain";22  }
页: [1]
查看完整版本: PHP与LDAP登录相关 ( Win 2008 R2 Server Domain Controller )