Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Access $_SESSION in Silverstripe Controller


Go to End


5 Posts   1051 Views

Avatar
salt_paper

Community Member, 4 Posts

18 July 2013 at 3:11pm

Hi,

We are using silverstripe as a CMS and the core product is separate but both on same domain. So all session management is doing by other product using PHP native sessions.

What i want is to access the session variable in Silverstripe to show whether the use is logged in or not.

$username = $_SESSION['username'].

Avatar
swaiba

Forum Moderator, 1899 Posts

18 July 2013 at 3:21pm

better to use..

if ($member = Member::currentUser()) {
return $member->FirstName;
}

Avatar
salt_paper

Community Member, 4 Posts

18 July 2013 at 3:35pm

Thanks for reply.

Both SS and other website lie on same domain. I have started the session in other website. Now what i want is to get the session value by $_SESSION in SS. Can i?

What this code do, does Member::currentUser() access the current session or what?

if ($member = Member::currentUser()) {
return $member->FirstName;
}

Avatar
swaiba

Forum Moderator, 1899 Posts

18 July 2013 at 3:51pm

>>What this code do, does Member::currentUser() access the current session or what?

Simple answer - read it - it is open source.
But yes it does.

>>Can i?

yes
$_SESSION['loggedInAs']

not hard to see if you just do

print_r($_SESSION);

Avatar
salt_paper

Community Member, 4 Posts

19 July 2013 at 10:07am

Thanks i sorted out. :)