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 8285279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:25:52+00:00 2026-06-08T11:25:52+00:00

I am having trouble retrieving some data out of an LDAP attribute in PHP.

  • 0

I am having trouble retrieving some data out of an LDAP attribute in PHP.

I connect to LDAP, perform my query, and store the results in a var like so:

$info = ldap_get_entries($connect, $sr);

Now, I can store most of the LDAP attributes I need in sessions vars, like so:

        $_SESSION['accountFirstName'] = $info[0]['givenname'][0];
        $_SESSION['accountLastName'] = $info[0]['sn'][0];
        $_SESSION['accountEmail'] = $info[0]['mail'][0];

These work fine.. No problems. However, there is another var I need to store. I believe It is an associative array. For some reason, no matter what I do, I am getting an NOTICE: Undefined index warning for that specific attribute. I have tried storing it like the above demonstration, but to be honest I’m not entirely sure what the [0] indices on either ends of the attribute name mean.. I’m not familiar with LDAP and frankly the setup is very confusing.

So I guess my questions are:

  • how do you access associative arrays that are returned from an LDAP
    query?

  • what does ‘undefined index’ mean? Does it mean that that
    attribute does not exist, or it does not exist at the index provided?

  • How can I test my LDAP query to see if the variable even exists?

  • There is a possibility that the account performing the query does not
    have adequate LDAP access privileges (the project is for a university
    and there is a lot of red tape). Is there any way for me to verify
    that through code?

Thank you! And my apologies for the vagueness of the information provided, I can’t be too open-mouthed right now.

  • 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-06-08T11:25:54+00:00Added an answer on June 8, 2026 at 11:25 am

    The issue doesn’t reside with the ldap_get_entries() method, or LDAP at all – it’s the data that’s being returned.

    The NOTICE: Undefined index error is stating that an index in your array doesn’t exist. In this case, it is most likely that the data you’re receiving doesn’t have a value such as givenname or mail, but it could also be the [0] (or, “first record”) in one of those arrays.

    The textual/string index value, such as givenname or sn, is what would be defined as the “associative array”. You are correctly accessing that data with $info[0]['givenname'];

    To check if an index exists in PHP, you can use isset(), such as:

    if (isset($info[0]['givenname'])) {
        // process data here
    }
    

    As a quick way to do your assignments, you can use something like this:

    if (count($info) > 0) {
        $_SESSION['accountFirstName'] = (isset($info[0]['givenname']) && isset($info[0]['givenname'][0])) ? $info[0]['givenname'][0] : '';
    }
    

    If you have a long list of values you need, I would suggest writing something similar to the following to auto-process it for you:

    $fields = array(
        'accountFirstName' => 'givenname',
        'accountLastName' => 'sn',
        'accountEmail' => 'mail'
    );
    
    $info = $info[0];
    foreach ($fields as $field => $ldapField) {
        // check if the value exists; otherwise set it to an empty-string
        $_SESSION[$field] = (isset($info[$ldapField]) && isset($info[$ldapField][0])) ? $info[$ldapField][0] : '';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I'm having some trouble with this code for retrieving Google Analytic data. if($_GET['month']
I´m having some trouble retrieving a collection of strings in a projection: say that
I'm having trouble storing and retrieving a float in NSUserDefauts. I store the value,
I am having trouble retrieving float/real values out of PostgreSQL. For example, I would
I must be missing something simple here, but I'm having trouble retrieving data from
I am building a core data iphone app, and having trouble with retrieving one-many
I'm having some trouble storing and retrieving items into a list<> with a custom
I'm having trouble retrieving JSONP data from one of my sites. On Site A
I'm having trouble retrieving data from my database using Spring Jdbc. Here's my issue:
I'm having trouble retrieving data from the google api. When I run the code,

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.