Jump to:

23376 Posts in 18218 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Access $_SESSION in Silverstripe Controller

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

Page: 1
Go to End
Author Topic: 317 Views
  • salt_paper
    Avatar
    Community Member
    4 Posts

    Access $_SESSION in Silverstripe Controller Link to this post

    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'].

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: Access $_SESSION in Silverstripe Controller Link to this post

    better to use..

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

  • salt_paper
    Avatar
    Community Member
    4 Posts

    Re: Access $_SESSION in Silverstripe Controller Link to this post

    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;
    }

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: Access $_SESSION in Silverstripe Controller Link to this post

    >>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);

  • salt_paper
    Avatar
    Community Member
    4 Posts

    Re: Access $_SESSION in Silverstripe Controller Link to this post

    Thanks i sorted out.

    317 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.