XAMPP本地主机上的LDAP

XAMPP本地主机上的LDAP,ldap,Ldap,我使用的是WindowsXP和XAMPP1.6.4-PHP5.2.4,并启用了LDAP trying this script : $server = "ldap://127.0.0.1/"; $user = "Salman"; $pass = "123"; $con = ldap_connect($server); ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($con, LDAP_OPT_REFER

我使用的是WindowsXP和XAMPP1.6.4-PHP5.2.4,并启用了LDAP

trying this script :
$server = "ldap://127.0.0.1/";
$user = "Salman";
$pass = "123";

$con = ldap_connect($server);

ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($con, LDAP_OPT_REFERRALS, 0);

var_dump(ldap_bind($con, $user, $pass)); 
但ldap_bind始终返回以下错误: 警告:ldap_bind()[function.ldap bind]:无法绑定到服务器:无法在第11行的D:\xampp\htdocs\test.php中联系ldap服务器
bool(false)

嗨,我前一阵子为这个问题组织了一个类:

    <?php

    /* USAGE:
     * $ldapObj= new Ldap("HOST","PORT","USERNAME","PASSWORD","Distinguished Name","        (mailnickname=USERNAME)",array("*"));
    */

    class Ldap {

    enter code here
    public $ldaphost;
    public $ldapport;
    public $ldaprdn;
    public $ldappass;
    public $dn;
    public $filter;
    public $attributes;
    public $ad;
    public $ldapbind;
    public $ldapresults;
    public $ldapentries;
    public $ldaperror;
    public $ldapstatus;

    function __construct($ldaphost, $ldapport, $ldaprdn, $ldappass, $dn, $filter, $attributes) {
        $this->ldaphost = $ldaphost;
        $this->ldapport = $ldapport;
        $this->ldaprdn = $ldaprdn;
        $this->ldappass = $ldappass;
        $this->dn = $dn;
        $this->filter = $filter;
        $this->attributes = $attributes;
        $this->ad = ldap_connect($this->ldaphost);
        if ($this->ad) {

            $this->ldapbind = ldap_bind($this->ad, $this->ldaprdn, $this->ldappass);
            if ($this->ldapbind) {
                $this->ldapresults = ldap_search($this->ad, $this->dn, $this->filter, $this->attributes);
                $this->ldapentries = ldap_get_entries($this->ad, $this->ldapresults);
                $this->getSid();
                $this->ldapstatus = 1;
            } else {
                $this->ldaperror = "Unable to authenticate user";
                $this->ldapstatus = 0;
            }
            ldap_unbind($this->ad);
        } else {
            $this->ldaperror = "Could not connect to {$this->ldaphost}";
            $this->ldapstatus = 0;
        }
    }

    function getLdapEntry($entry) {
        return $this->ldapentries[0][$entry][0];
    }

    function getLdapEntries() {
        return $this->ldapentries;
    }

    function ldapError() {
        return $this->ldaperror;
    }

    function getSid() {
        $sid = "S-";
        $entries = $this->ldapentries;
// Convert Bin to Hex and split into byte chunks
        $sidinhex = str_split(bin2hex($entries[0]['objectsid'][0]), 2);
// Byte 0 = Revision Level
        $sid = $sid . hexdec($sidinhex[0]) . "-";
// Byte 1-7 = 48 Bit Authority
        $sid = $sid . hexdec($sidinhex[6] . $sidinhex[5] . $sidinhex[4] . $sidinhex[3] . $sidinhex[2] . $sidinhex[1]);
// Byte 8 count of sub authorities - Get number of sub-authorities
        $subauths = hexdec($sidinhex[7]);
//Loop through Sub Authorities
        for ($i = 0; $i < $subauths; $i++) {
            $start = 8 + (4 * $i);
            // X amount of 32Bit (4 Byte) Sub Authorities
            $sid = $sid . "-" . hexdec($sidinhex[$start + 3] . $sidinhex[$start + 2] . $sidinhex[$start + 1] . $sidinhex[$start]);
        }
        $this->sid = $sid;
    }
}
?>

您好,我前一段时间为这个项目组织了一个课程:

    <?php

    /* USAGE:
     * $ldapObj= new Ldap("HOST","PORT","USERNAME","PASSWORD","Distinguished Name","        (mailnickname=USERNAME)",array("*"));
    */

    class Ldap {

    enter code here
    public $ldaphost;
    public $ldapport;
    public $ldaprdn;
    public $ldappass;
    public $dn;
    public $filter;
    public $attributes;
    public $ad;
    public $ldapbind;
    public $ldapresults;
    public $ldapentries;
    public $ldaperror;
    public $ldapstatus;

    function __construct($ldaphost, $ldapport, $ldaprdn, $ldappass, $dn, $filter, $attributes) {
        $this->ldaphost = $ldaphost;
        $this->ldapport = $ldapport;
        $this->ldaprdn = $ldaprdn;
        $this->ldappass = $ldappass;
        $this->dn = $dn;
        $this->filter = $filter;
        $this->attributes = $attributes;
        $this->ad = ldap_connect($this->ldaphost);
        if ($this->ad) {

            $this->ldapbind = ldap_bind($this->ad, $this->ldaprdn, $this->ldappass);
            if ($this->ldapbind) {
                $this->ldapresults = ldap_search($this->ad, $this->dn, $this->filter, $this->attributes);
                $this->ldapentries = ldap_get_entries($this->ad, $this->ldapresults);
                $this->getSid();
                $this->ldapstatus = 1;
            } else {
                $this->ldaperror = "Unable to authenticate user";
                $this->ldapstatus = 0;
            }
            ldap_unbind($this->ad);
        } else {
            $this->ldaperror = "Could not connect to {$this->ldaphost}";
            $this->ldapstatus = 0;
        }
    }

    function getLdapEntry($entry) {
        return $this->ldapentries[0][$entry][0];
    }

    function getLdapEntries() {
        return $this->ldapentries;
    }

    function ldapError() {
        return $this->ldaperror;
    }

    function getSid() {
        $sid = "S-";
        $entries = $this->ldapentries;
// Convert Bin to Hex and split into byte chunks
        $sidinhex = str_split(bin2hex($entries[0]['objectsid'][0]), 2);
// Byte 0 = Revision Level
        $sid = $sid . hexdec($sidinhex[0]) . "-";
// Byte 1-7 = 48 Bit Authority
        $sid = $sid . hexdec($sidinhex[6] . $sidinhex[5] . $sidinhex[4] . $sidinhex[3] . $sidinhex[2] . $sidinhex[1]);
// Byte 8 count of sub authorities - Get number of sub-authorities
        $subauths = hexdec($sidinhex[7]);
//Loop through Sub Authorities
        for ($i = 0; $i < $subauths; $i++) {
            $start = 8 + (4 * $i);
            // X amount of 32Bit (4 Byte) Sub Authorities
            $sid = $sid . "-" . hexdec($sidinhex[$start + 3] . $sidinhex[$start + 2] . $sidinhex[$start + 1] . $sidinhex[$start]);
        }
        $this->sid = $sid;
    }
}
?>

是这方面的另一个线程。浏览一些答案,因为答案没有被接受。这是另一个线程。由于某个答案未被接受,请仔细查看一些答案。警告:ldap_bind()[function.ldap bind]:无法绑定到服务器:无法在第48行的D:\xampp\htdocs\test.php中联系ldap服务器警告:ldap_bind()[function.ldap bind]:无法绑定到服务器:无法在第48行的D:\xampp\htdocs\test.php中联系ldap服务器