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.

General Questions /

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

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

Access $_SESSION in Silverstripe Controller


Reply


5 Posts   445 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, 1805 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, 1805 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. :)