17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 4391 Views |
-
logout and session destroy

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>
<?
}
?> -
Re: logout and session destroy

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.
| 4391 Views | ||
|
Page:
1
|
Go to Top |


