如何使用var_dump()或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

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

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

Mean like that?

user_name: $_SESSION["_sf2_attributes"]["username"]

user_id: $_SESSION["_sf2_attributes"]["user_id"]

It's basic PHP:

$YourArray["_sf2_attributes"]["username"] $YourArray["_sf2_attributes"]["username"]

where $YourArray is, obviously, your array variable.

Hope this helps, but you probably want to do a basic PHP tutorial. Tizag.com do a decent one: http://tizag.com/phpT/