Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » logout and session destroy

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 4655 Views
  • bebabeba
    Community Member
    192 Posts

    logout and session destroy Link to this post

    Hi guy!
    I create a session for my login area..now I need logout user and destry session.
    So I use this function but is wrong because i can't destroy session. Then in thempalte if I insert Logout in that point I can't log in..
    function Logout()
       { if((Session::get('registrato', false)) //if my user log in
        session_destroy(); // I destroy session
        return Director::redirect('http://chimera2:81/m5/home/'); //I return in my homepage   

    and in template:

    if (Session::get('registrato') == 1) //user is log in
    <div><a href="$Logout">LOGOUT</a>      

  • Hamish
    Community Member
    712 Posts

    Re: logout and session destroy Link to this post

    You can't use plain PHP in a template.

    You need to create a 'checkSession' (or similar) function in the page class, and you can call the method from the template.

    // In the class:
    function isLoggedIn() {
    return (Session::get('registrato') == 1)

    // In the template
    <% if isLoggedIn %>
    <div><a href="$Logout">LOGOUT</a>
    <% end_if %>

    But, again, I encourage you to use the existing user administration functionality. You are reinventing the wheel.

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.