簡體   English   中英

如何獲取LDAP電話號碼?

[英]How can I fetch LDAP phone number?

下面的代碼為我提供了ldap用戶名和全名...我對LDAP有點陌生,所以我想知道如何獲取用戶電話號碼?

我需要添加到代碼中以使其也呼出電話號碼的是什么?

<?php

$x=1;
if($x==1)
{
    //LDAP stuff here.
    $username = "stuff";
    $password = "stuffhere";

    echo("Authenticating...");
    $ds = ldap_connect('ldap host');

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

    //Can't connect to LDAP.
    if( !ds )
    {
        echo "Error in contacting the LDAP server -- contact ";
        echo "technical services!  (Debug 1)";

        exit;
    }

    //Connection made -- bind anonymously and get dn for username.
    $bind = @ldap_bind($ds);

    //Check to make sure we're bound.
    if( !bind )
    {
        echo "Anonymous bind to LDAP FAILED.  Contact Tech Services! (Debug 2)";

        exit;
    }

    $search = ldap_search($ds, "rdn here", "uid=$username");

    //Make sure only ONE result was returned -- if not, they might've thrown a * into the username.  Bad user!
    if( ldap_count_entries($ds,$search) != 1 )
    {
        echo "Error processing username -- please try to login again. (Debug 3)";
        redirect(_WEBROOT_ . "/try1b.php");

        exit;
    }

    $info = ldap_get_entries($ds, $search);

    //Now, try to rebind with their full dn and password.
    $bind = @ldap_bind($ds, $info[0][dn], $password);
    if( !$bind || !isset($bind))
    {
        echo "Login failed -- please try again. (Debug 4)";
        redirect(_WEBROOT_ . "/try1b.php");

        exit;
    }

    //Now verify the previous search using their credentials.
    $search = ldap_search($ds, "rdn here", "uid=$username");

    $info = ldap_get_entries($ds, $search);
    if( $username == $info[0][uid][0] )
    {
echo $username;
     echo $info[0][cn][0]; 


        exit;
    }
    else
    {
        echo "Error. Access Denied";
        redirect(_WEBROOT_ . "/try1b.php");

        exit;
    }
    ldap_close($ds);
    exit;
}
?> 

RFC4519給出telephoneNumber作為標准用戶模式的電話號碼的屬性。 在搜索請求的請求屬性列表中列出此屬性。 有關查詢目錄服務器的更多信息,請參見“ LDAP:使用ldapsearch”“ LDAP:編程實踐”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM