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

problem with session


Go to End


1334 Views

Avatar
bebabeba

Community Member, 193 Posts

4 December 2008 at 3:24am

hi!
can you hel me with session? I want that only admin user can see some reserved page. So I have a login area. when a user log as admin in my menu appear other 2 voice. so a normal user can see onlu homepage, admin user ca see homepage, page 1 and page 2.
It's ok after login but when admin click on page1 or page 2 I see content page but in my menu that voice disappear. I think this is a problem session.
I post my code can you help me to correct?

in _config I put: $GLOBALS['a'] = 0;

in page.php:
function doLogin($data, $form) {
global $a;

if((($data['nome']) == 'admin')&&(($data['password']) == 'admin'))
{ Session::set('utente_loggato', true);

$a=1;
$var = array('var' => $a);
}
else {
$a=0;
$var = array('var' => $a);
}
return $var;
}

function sessione_attiva()
{
return Session::get('utente_loggato');
}

and in my template:
<% if var = 1 %>
$sessione_attiva

<ul>
<% control Menu(1) %>
<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle</span></a></li>
<% end_control %>
</ul>
<% end_if %>