how to modify header based on whether user's logged in?

This is an archive of the phpBB 2.0.x support forum. Support for phpBB2 has now ended.
Forum rules
Following phpBB2's EoL, this forum is now archived for reference purposes only.
Please see the following announcement for more information: viewtopic.php?f=14&t=1385785
Locked
tada
Registered User
Posts: 5
Joined: Thu Feb 24, 2005 7:27 am

how to modify header based on whether user's logged in?

Post by tada »

Hi,

I'd like to modify the header so that users who haven't logged in will only see "FAQ, Search, Register", while logged-in users will see the complete list (including Profile, Memberlist and etc)

Could somebody tell me how I can do that?

Thanks a lot :)

User avatar
golddust
Registered User
Posts: 423
Joined: Tue Mar 09, 2004 4:41 am
Location: UK

Post by golddust »

You will need to place your choosen code between the switch tags <!-- ---> as shown in the example below, depending on what you want to show - ie Log in or Log out.



EXAMPLE
<!-- BEGIN switch_user_logged_in -->
<a href="{U_LOGIN_LOGOUT}" title="Log in/out"><img src="../../../../images/log-in-7a.gif" alt="Log out" width="72" height="23" /></a>
<!-- END switch_user_logged_in -->

<!-- BEGIN switch_user_logged_out -->
<a href="{U_REGISTER}" title="Register">
<img src="../../../../images/register-9.gif" width="88" height="23" /></a>
<!-- END switch_user_logged_out -->



Hope that helps ;-)

tada
Registered User
Posts: 5
Joined: Thu Feb 24, 2005 7:27 am

thanks :)

Post by tada »

thanks, it works perfectly :)

Colliope
Registered User
Posts: 67
Joined: Sat Feb 05, 2005 3:16 am
Contact:

Post by Colliope »

Could you show me what to move where in the code to make the member_list appear only when logged IN?

Code: Select all

 <a href="{U_FAQ}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_faq.gif" alt="{L_FAQ}" border="0"></a>
						  &nbsp;<a href="{U_PROFILE}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_profile.gif" border="0" alt="{L_PROFILE}"></a> 
                  &nbsp;<a href="{U_PRIVATEMSGS}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_message.gif" border="0" alt="{PRIVATE_MESSAGE_INFO}"></a> 
                  &nbsp;<a href="{U_GROUP_CP}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_groups.gif" alt="{L_USERGROUPS}" border="0"></a> 
                  &nbsp;<a href="{U_MEMBERLIST}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_members.gif" border="0" alt="{L_MEMBERLIST}"></a> 
                  &nbsp;<a href="{U_SEARCH}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_search.gif" border="0" alt="{L_SEARCH}"></a> 


          <!-- BEGIN switch_user_logged_in -->
                  &nbsp;<a href="{U_LOGIN_LOGOUT}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_logout.gif" border="0" alt="{L_LOGIN_LOGOUT}"></a> 
          <!-- END switch_user_logged_in -->

<!-- BEGIN switch_user_logged_out -->
                  &nbsp;<a href="{U_REGISTER}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_register.gif" border="0" alt="{L_REGISTER}"></a> 
                  &nbsp;<a href="{U_LOGIN_LOGOUT}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_login.gif" border="0" alt="{L_LOGIN_LOGOUT}"></a> 
          <!-- END switch_user_logged_out -->

Do I just take this part

Code: Select all

 &nbsp;<a href="{U_MEMBERLIST}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_members.gif" border="0" alt="{L_MEMBERLIST}"></a> 
and move into this part

Code: Select all

<!-- BEGIN switch_user_logged_in -->
                  &nbsp;<a href="{U_LOGIN_LOGOUT}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_logout.gif" border="0" alt="{L_LOGIN_LOGOUT}"></a> 
          <!-- END switch_user_logged_in -->
? That seems like the logical thing to do, but I'm not sure how moving that part of the code effects where on the screen the member-list icon will appear.
Col

User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34457
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Post by A_Jelly_Doughnut »

You could just change

Code: Select all

&nbsp;<a href="{U_MEMBERLIST}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_members.gif" border="0" alt="{L_MEMBERLIST}"></a>
to

Code: Select all

<!-- BEGIN switch_user_logged_in -->
&nbsp;<a href="{U_MEMBERLIST}" onFocus="if(this.blur)this.blur()"><img src="templates/Diddle/images/{LANG}icon_mini_members.gif" border="0" alt="{L_MEMBERLIST}"></a>
<!-- END switch_user_logged_in -->
to leave the locatin alone.
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish

tsjakkaa
Registered User
Posts: 261
Joined: Sat Mar 27, 2004 1:25 pm
Location: belgium
Contact:

Post by tsjakkaa »

if the purpose is to make the memberlist only accessible when logged in , it'll aks for some more code. take a look at this topic
http://www.phpbb.com/phpBB/viewtopic.ph ... =0#1377119

I would let the memberlist-link on the page, even when not logged in. And do the control when entering the memberlist page. This solution will have less problems with the layout
Image

Colliope
Registered User
Posts: 67
Joined: Sat Feb 05, 2005 3:16 am
Contact:

Post by Colliope »

I just checked out that thread and want to make sure I came away with the correct info - that this is all I have to do to send unregistered visitors to the log-in page if they click on the member list icon:

[OPEN]
memberlist.php

[FIND]
// End session management
//


[AFTER,ADD]

// Begin 'Restrict Guest Access' MOD
if ( !$userdata['session_logged_in'] )
{
redirect(append_sid("index.".$phpEx."?restrict=memberlist.".$phpEx, true));
exit;
}
// End 'Restrict Guest Access' MOD


[RESULT]
// End session management
//
// Begin 'Restrict Guest Access' MOD
if ( !$userdata['session_logged_in'] )
{
redirect(append_sid("index.".$phpEx."?restrict=memberlist.".$phpEx, true));
exit;
}
// End 'Restrict Guest Access' MOD

So the result has 4 //// between "end session management" and "begin restrict.." ? And I see the "index" probably need to be changed to the log-in page name, but not sure what that would be.

Col

tsjakkaa
Registered User
Posts: 261
Joined: Sat Mar 27, 2004 1:25 pm
Location: belgium
Contact:

Post by tsjakkaa »

Code: Select all

/ Begin 'Restrict Guest Access' MOD
if ( !$userdata['session_logged_in'] )
   {
      redirect(append_sid("login.".$phpEx."?redirect=memberlist.".$phpEx, true));
      exit;
   }
// End 'Restrict Guest Access' MOD
you'll have to insert this in memberlist.php
there where 2 errors
- it's redirecting to the index-page, instead of login
- it's using the wrong parameter, it should be "redirect=" instead of "restrict"

I've tested this on a test-board (place after the session management in memberlist.php)
Image

jongartman
Registered User
Posts: 57
Joined: Tue May 11, 2004 8:17 am

Post by jongartman »

i've got a similar question: can you use those switches ANYWHERE on a phpbb installation? for example, i've rigged up a page that dynamically displays all the mods and admins on my board for users logged in or not - if for some reason i wanted to have only the admins viewable to the admins, could i put an admin switch around that section of the page? keep in mind this is not a regular page on a vanilla phpbb install, but it does query the database to get username type things. do i have to 'pass' anything to this extra page or will phpbb catch it and do the switch for me?

Colliope
Registered User
Posts: 67
Joined: Sat Feb 05, 2005 3:16 am
Contact:

Post by Colliope »

tsjakkaa
Thanks that worked great. Could you possibly tell me how/where to do the same thing for the search icon?

Col

Locked

Return to “2.0.x Support Forum”