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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

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

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

logout and session destroy

Go to End

2 Posts   5723 Views


Community Member, 193 Posts

12 December 2008 at 9:47pm

Hi guy!
I create a session for my login 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>


Community Member, 712 Posts

15 December 2008 at 11:46am

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.