2011-10-31 187 views
0

下面的代碼讓我知道ldap的用戶名和全名...我對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; 
} 
?> 
+0

您應該能夠在返回的信息中看到它。在你打印出用戶名的地方添加:echo「

".print_r($info[0],true)."

」; –

回答