drl47263 2015-10-27 09:42
浏览 150
已采纳

如何绑定到ldap中的特定ou

I want to be able to allow a single ou in Active directory to have authentication access to an internal website of my company. Please help as I have wasted too much time on it. This is what I have got so far:

$domain ='ab.cd.ef.gh.ij';
        $host='xxx.xxx.xx.x';
        $ds = ldap_connect($host); //has to be domain or hostname
        ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
        ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);

        if($ds)
        {

            $bind=ldap_bind($ds,$name, $pass);
            if($bind)
            {
                $_SESSION['status'] = 'authorized';
                header("location: index.php");
            } else return "Please enter correct username and password.";
        }

Thanks in advance

  • 写回答

1条回答 默认 最新

  • douxia2137 2015-10-28 09:45
    关注

    This works perfect if you want to allow one ou to have access to a login system :

    $domain ='ab.cd.ef.gh.ij';
            $host='xxx.xxx.xx.x';
            $connect = ldap_connect($host); //has to be domain or hostname
            ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
            ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
            $dn = "OU=something,OU=something,OU=something,OU=something,DC=ab,DC=cd,DC=ef,DC=gh,DC=ij";
            $search = "CN=$name";  
    
            if($connect)
            {
                $bind=ldap_bind($connect,$name, $pass);
                if($bind)
                {
                    $sr=ldap_search($connect, $dn, $search);
                    $data = ldap_get_entries($connect, $sr);
                    for ($i=0; $i<$data["count"]; $i++) 
                    {
                         $user = $data[$i]["dn"] ;
                    }
                     if($user =="CN=$name,OU=something,OU=something,OU=something,OU=something,DC=ab,DC=cd,DC=ef,DC=gh,DC=ij")
                    {
                        $_SESSION['status'] = 'authorized';
                        header("location: index.php");
                    }else
                    {
                    header("location:lost.html");
                    }
    
                } else return "Please enter correct username and password.";
            }
    

    The only down side to this is that the username and the common name has to be the same for this to work.

    Happy Coding

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘