0

I have a small problem. I'm trying to extract data from [user] but I can seem to get it right. Can someone please give me one example of how to extract for example the users id and from there I'm golden. This is the $_SESSION array (what the session contains), if that's any help.

 Array ( [__default] => Array ( 
                            [session.counter] => 3
                            [session.timer.start] => 1307209662 
                            [session.timer.last] => 1307209693 
                            [session.timer.now] => 1307209701 
                            [session.client.browser] => Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 
                            [registry] => JRegistry Object ( 
                                                            [_defaultNameSpace] => session
                                                            [_registry] => Array ( 
                                                                                    [session] => Array ( 
                                                                                                        [data] => stdClass Object ( ) 
                                                                                                        ) 
                                                                                ) 
                                                            [_errors] => Array ( ) 
                                                            ) 
                            [user] => JUser Object ( 
                                                    [id] => 0 
                                                    [name] => 
                                                    [username] => 
                                                    [email] => 
                                                    [password] => 
                                                    [password_clear] => 
                                                    [usertype] => 
                                                    [block] => 
                                                    [sendEmail] => 0 
                                                    [gid] => 0 
                                                    [registerDate] => 
                                                    [lastvisitDate] => 
                                                    [activation] => 
                                                    [params] => 
                                                    [aid] => 0 
                                                    [guest] => 1 
                                                    [_params] => JParameter Object ( [_raw] => 
                                                                                    [_xml] => 
                                                                                    [_elements] => Array ( ) [_elementPath] => Array (                                                                                                                                                              [0] => C:\xampp\htdocs\libraries\joomla\html\parameter\element )
                                                                                                                                                            [_defaultNameSpace] => _default 
                                                                                                                                                            [_registry] => Array ( 
                                                                                                                                                                                    [_default] => Array ( 
                                                                                                                                                                                                        [data] => stdClass Object ( ) 
                                                                                                                                                                                                        ) 
                                                                                                                                                                                ) 
                                                                                                                                                            [_errors] => Array ( ) 
                                                                                    ) 
                                                    [_errorMsg] => [_errors] => Array ( ) 
                                                    ) 
                            [session.token] => 971893bd69fff85ea2a006788a28b15d 
                        ) 
    [referrerid] => AUPRS-JOHNDOE
    )
3
  • Welcome to Stack Overflow - one of the best ways to help people answer your question is to nicely format any code in your question. Check out the helpful notes here: stackoverflow.com/editing-help Commented Jun 6, 2011 at 17:49
  • If this is a Joomla session, then there are probably wrapper functions which can accomplish getting some user information. Also, how exactly did you try to access the data? Commented Jun 6, 2011 at 17:51
  • i'm trying to include some scripts into my joomla based site, one example would be ajaxim from ajaxim.com and i need to check outside joomla if the user is logged in, to extract his username,id,password and other related info about him to use in ajaxim or future scripts that i want to integrate. Commented Jun 6, 2011 at 18:33

2 Answers 2

1
$user = $_SESSION['user'];
echo $user->id;

This seems to be what you need.

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

Comments

0

This would output the user name: (if there was any)

 print $_SESSION["__default"]["user"]->name;

You first need to overcome the __default key index within the $_SESSION array. Likewise is user an array key. But what the user entry contains is an object, so you need the -> object arrow thingy to finally access the name.

Also I would not rely on __default being a given. Don't know anything about Joomla, but the $_SESSION array structure might be more flexible. Hencewhy it's advisable to find a function which instead fetches the user object for you.

1 Comment

Mario, i eventualy found a solution, but it wasn't as elegant and clean as yours so i ditched it for yours. Your solution is perfect. For refference, my not so clean solution was this function getvalue($value,$key,$what) { $info[$key]=$value; echo $info[$what]; } $array=$_SESSION['__default']['user']; array_walk($array,"getvalue","username");

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.