LDAP на локальном хосте XAMPP - PullRequest
2 голосов
/ 31 января 2012

Я использую Windows XP с XAMPP 1.6.4 - php 5.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]: Невозможно привязать к серверу: Невозможно связаться с сервером LDAP в D: \ xampp \ htdocs \ test.php в строке 11 BOOL (ложь)

1 Ответ

0 голосов
/ 31 января 2012

Привет, я собрал класс на некоторое время назад:

    <?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;
    }
}
?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...