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.

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   6254 Views

Avatar
bebabeba

Community Member, 193 Posts

12 December 2008 at 9:47pm

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

Avatar
Hamish

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.