1

My page accepts users through invitation codes to take surveys using UCCASS, and inspecting the session data goes as follows:

print_r($_SESSION);
[invite_code_type] => alphanumeric
[invite_code_length] => 10
[priv] => Array
    (
        [37] => Array
            (
                [2] => 1
                [3] => 1
                [name] => William
                [email] => will@william.com
                [uid] => 58
            )
    )
)

How would I simply extract the current session's values for a welcome screen like this:

"Hello William"

I tried the following without any luck:

echo "Welcome " . $_SESSION['name'] . "<*br>";
Flygenring
  • 3,818
  • 1
  • 32
  • 39

3 Answers3

3

Well that's how your taking value is not right.

But if 37 never changes, You can take it $_SESSION['priv'][37]['name']

But if key 37 will be varriable, then You have to loop all of them for example:

foreach($_SESSION['priv'] as $user)
{
    echo $user['name'];
}

Something like this.

Lolipopcoder
  • 145
  • 9
  • 37 represents the survey's ID , so if a user takes survey ID 38 the loop works with your code, thinking ahead of the problem there – Ramses Velasco Nov 26 '17 at 03:32
2
echo "Welcome ".$_SESSION[priv][37]['name'] . "<*br>";

But i think your [37] is set there in a dynamic way so i suggest a foreach loop around $_SESSION[priv] so you can access all the keys beneath it and then you just get the ['name'] of each the same way i showed you and store it inside a new array which you are going to display it in your welcome message.

pr1nc3
  • 8,108
  • 3
  • 23
  • 36
0
echo "Welcome ".$_SESSION['priv'][37]['name'] . "<br/>";

foreach($_SESSION['prev'] as $key=>$value)
{
  foreach($values as $key=>$value)
     {
              echo $value['name'];
     }

}