LDAP 连接 PHP 问题

LDAP Connection with PHP Issue

我目前正在尝试连接到我们的 Active Directory 以执行一些奇特的搜索魔术。我在 python 中编写了所有花哨的搜索,现在我们只是试图将其移植到 PHP。我无法正常连接到 ldap 服务器。我没有收到任何错误消息,也没有显示我的信息回显,我的页脚也没有。任何帮助,将不胜感激!谢谢!

代码如下:

<?php
    include "src/header.php";
    echo "Well Hello-01<br>";

    if(isset($_POST['username'])){
        $User = 'AD\' . $_POST['username'];
    }
    if(isset($_POST['password'])){
        $Pass = $_POST['password'];
    }



    echo "Username: " . $User . "<br>";
    echo "Password: " . $Pass . "<br>";

    $ldapconn = ldap_connect("ldap://ad.whatever.com")
         or die("Could not connect to LDAP server");

    if($ldapconn){  
        echo "Attempting Bind";
        //binding to ldap 
        $ldapbind = ldap_bind($ldapconn, $User, $Pass);

        //Verify Bind
        if($ldapbind){
            echo "LDAP bind successfull...";
        }else{
            echo "LDAP bind failed...";
        }
    }else{
        echo "Fail";
    }

    include "src/footer.php";
?>

</body>`

不管这里的值是什么,输出到屏幕的是:Screenshot

我刚才做了这个代码,也许它可以帮助你:

<?php
    $username = $_POST['USERNAME'];
    $password = $_POST['USERPASS'];
    $server = 'AD_SERVER_IP_GOES_HERE';
    $domain = '@MY_DOMAIN.COM'; 
    $port = 389; //default connection port
    $dn = "DC=MY_DOMAIN,DC=COM";
    $filter = "(&(samaccountname=".$username."))";
    $params = array("sn","givenName","samAccountName",
                     "mail","displayName","department",
                     "title","company","streetAddress",
                     "department","memberOf");

    /*these are parameters you want to retrieve from a given user*/


    $connection = ldap_connect($server, $port);
        if (!$connection) {
        echo 'no_server';

    }


    $bind = @ldap_bind($connection, $username.$domain, $password);
    if (!$bind) {
        echo 'user_error';
    }
    else
    {
        $query_user = ldap_get_entries($connection,ldap_search($connection,$dn,$filter,$params));

        print_r($query_user);
    }

    // Close conection

    ldap_close($connection);

}

?>