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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

creating a logout link

Go to End

10 Posts   9638 Views


Community Member, 1 Post

24 December 2010 at 1:17am


I think this is more simple and helped me alot.

// mysite/code/Page.php -> Page_Controller

	public function IsLoggedIn(){
			return true;

	public function CurrentUser(){
		return Member::currentUser();		

// In your template File

	<% if IsLoggedIn %>
		<li id="logged-in" class="mainmenu">
			<% control CurrentUser %>
				<span>You are logged in as </span>
					<% if FirstName && Surname %>
						$FirstName $Surname
					<% else_if FirstName %>
					<% else %>
					<% end_if %>
				(<a href="Security/logout" id="LogoutLink">Logout</a>)
			<% end_control %>
	<% else %>
		<li id="login" class="mainmenu"><a href="Security/login?BackURL=$Link">Login</a></li>
	<% end_if %>


Optic Blaze

Community Member, 175 Posts

21 December 2013 at 3:29am


When creating a logout link in Silverstripe 3.1 i got the following error:
[Strict Notice] Non-static method Security::logout() should not be called statically ....

Looked at the docs. And used the following in page.php Also created link in .ss template as per earlier posts on this topic

public function logout($redirect = true) {
$member = Member::currentUser();
if($member) $member->logOut();

This worked for me

Go to Top