2

I have weird problem where I'm storing some data in the $_SESSION variable. The problem lies between line 8 and 9. Somehow data is not stored in the session. And I'm clueless where the problem can lie.

When assigning the $data variable to session, it works, but when assining something from $data to session it doesn't work! But the line 7 shows me that accessing the $data array works.

Where is the problem?

Here link is an example of print_r($_SESSION)

code:

 1: $ldap = new adLDAP();
 2: $ldap->authenticate($username, $password);
 3: $ldapUser = $ldap->user();
 4: $data = $ldapUser->info($username, $this->ldapInfo);
 5: $managerArr = explode(',', $data[0]['manager'][0]);
 6: $managerCN = explode('=', $managerArr[0]);
 7: $this->log->debug("Display Name = " . $data[0]['displayname'][0]);
 8: //$_SESSION['ldap_raw'] = $data; // <--- this freakin works
 9: $_SESSION[UserDetails::sessionInfoName][UserDetails::sessionInfoTitleName] = $data[0]['title'][0];
10: $_SESSION[UserDetails::sessionInfoName][UserDetails::sessionInfoTelephoneNumber] = $data[0]['telephonenumber'][0];
11: $_SESSION[UserDetails::sessionInfoName][UserDetails::sessionInfoDisplayNameName] = $data[0]['displayname'][0]);

UserDetails::sessionInfoName and UserDetails::sessionInfoXXXXYYYY are constants defined in the class UserDetails

13
  • 1
    Please provide UserDetails::sessionInfo* and $data most likely you're referencing array keys that don't exist (and ignoring the notices). Commented Jun 25, 2013 at 9:50
  • 3
    @AvnerSolomon why do you say that? Commented Jun 25, 2013 at 9:50
  • 2
    Try $_SESSION[UserDetails::sessionInfoName] = array() first Commented Jun 25, 2013 at 9:51
  • 1
    @jcubic, you're not at "Stackoverflow: the Question and Guesses website" Commented Jun 25, 2013 at 9:53
  • 2
    @AvnerSolomon What one earth do you mean!!?? The is a one of several methods you can set a value in an array and as $_SESSION is an array, of course you can use it like that! Commented Jun 25, 2013 at 9:55

1 Answer 1

2

The issue is obviously NOT to do with session_start() as you have clearly stated that it works when you explicitly set the array key.

You must follow the following steps to determine what the issue is:

  1. Print the UserDetails object and ensure the values you are retrieving are set AND also ensure they are public.
  2. Print $data to ensure that you have the right levels set in your array. For instance, you are referencing $data[0]['title'][0], this might actually be $data[0]['title'].

This is likely to just be a minor error in the variables/objects you are referencing as there is nothing syntactically incorrect with your code, therefore printing this data should reveal what the issue is!

Do the following:

$ldap = new adLDAP();
$ldap->authenticate($username, $password);
$ldapUser = $ldap->user();
$data = $ldapUser->info($username, $this->ldapInfo);
$managerArr = explode(',', $data[0]['manager'][0]);
$managerCN = explode('=', $managerArr[0]);
$this->log->debug("Display Name = " . $data[0]['displayname'][0]);

// Print the $data array
print_r($data);

// Print the UserDetails object instance
print_r(UserDetails);

exit;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.