Search code examples
phpiframevar-dump

How can i get just the session username using var_dump() or print_r()


I tried getting session information on my iframe using var_dump(). I got this output.

`array(3) {
  ["_sf2_attributes"]=>
  array(5) {
    ["identity"]=>
    string(18) "xxxxxxxxxxx"
    ["username"]=>
    string(17) "xxxxxxxxxxxx"
    ["email"]=>
    string(18) "xxxxxxxxxxxx"
    ["user_id"]=>
    string(2) "xx"
    ["old_last_login"]=>
    string(10) "xxxxxxxxx"
  }
  ["_sf2_flashes"]=>
  array(0) {
  }
  ["_sf2_meta"]=>
  array(3) {
    ["u"]=>
    int(xxxxxxxxx)
    ["c"]=>
    int(xxxxxxxxx)
    ["l"]=>
    string(1) "0"
  }
}

`

How can I extract just the user-name and user-id, to use on my iframe? Thanks


Solution

  • simply by accessing the array indexes. assuming the content you provided is stored in a variable called $session

    echo $session['_sf2_attributes']['username'];