Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6743739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:59:51+00:00 2026-05-26T11:59:51+00:00

The code below gets me the ldap username and full name…I am a little

  • 0

The code below gets me the ldap username and full name…I am a little new to LDAP so I was wondering how may I also get the user phone number?

What is it that I need to add to my code to make it echo out the phone number as well?

<?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;
}
?> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:59:52+00:00Added an answer on May 26, 2026 at 11:59 am

    RFC4519 gives telephoneNumber as the attribute for a phone number in the standard user schema. List this attribute in the requested attributes list in the search request. For more information about query a directory server, see "LDAP: Using ldapsearch" and "LDAP: Programming Practices".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below gets the username/password and runs it thru the backend.php script. <?php
In the below code, the ListBox gets filled with the names of the colors
I have below is the html code for TD which gets appended after matching
I have an application that displays videos. The code below gets a list of
In the code below ViewState[L] stores a List<string> . I create a new instance
As far as I know, the code below gets a shape from the active
The code below works fine if factors is small but when it gets larger
The code below gets the information i require from my database but is not
please refer to the code below. $dArr = '<script>document.write(volunteerDist);</script>'; $dArr gets the value of
The code below is supposed to check whether the name already exists in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.