TinyPortal

Development => Support => Topic started by: General_Sun on July 14, 2007, 08:58:42 PM

Title: Creating a Working logout link
Post by: General_Sun on July 14, 2007, 08:58:42 PM
I tried to use the menu to create a logout link.

Could someone paste the code to create such a link? forum/index.php?action=logout doesn't work, there's some session id stuff after it. I am not proficient enough to get the working link on my own. Please help!
Title: Re: Creating a Working logout link
Post by: IchBin on July 15, 2007, 03:46:08 AM
You can't create a link like that in the menu manager. It requires the session ID to be added to the logout link which would be in the context array. In other words, you can't use PHP in the menu manager. You'll have to create a custom menu to do that in a block or something.
Title: Re: Creating a Working logout link
Post by: General_Sun on July 15, 2007, 04:02:44 AM
Yikes, Perhaps I could create a custom block just for that. What kind of code would be involved?
Title: Re: Creating a Working logout link
Post by: IchBin on July 15, 2007, 04:19:26 AM
If you look at the logout button in the template_menu  function in the index.template.php file you can see how the $context['session_id'] is added to the link.
Title: Re: Creating a Working logout link
Post by: General_Sun on July 15, 2007, 05:15:02 AM
Yes ok. So I'm looking at index template and here's the relevant code:

// Otherwise, they might want to [logout]...
if ($context['user']['is_logged'])
echo ($current_action == 'logout' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
<td valign="top" class="maintab_' , $current_action == 'logout' ? 'active_back' : 'back' , '">
<a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">' , $txt[108] , '</a>
</td>' , $current_action == 'logout' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';


This is just too much junk. I don't want any of the maintab stuff. Just dumping all this into the php box does produce a logout button in some strange place but destroys the layout.

I need to refine this code.

The URL is here:

<a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">' , $txt[108] , '</a>

But that alone gives me:
Parse error: syntax error, unexpected '<' in /home/.luther/generalsun/miydai/Sources/Load.php(1797) : eval()'d code(35) : eval()'d code on line 1

I'll experiment some more...

I really regret not knowing php fully. This is like groping in the dark...
Title: Re: Creating a Working logout link
Post by: tick on July 15, 2007, 05:17:11 AM
If you hover over the logout button on your forum look down at the bottom left corner of the browser window and it will show you the url for the logout.  Try that.



Edit :  That will not work I dont think but try it
Title: Re: Creating a Working logout link
Post by: General_Sun on July 15, 2007, 05:24:19 AM
Ehh thanks, but read my first post, I've already tried something similar.
Title: Re: Creating a Working logout link
Post by: tick on July 15, 2007, 05:38:04 AM
I just tried what I posted above and it works for me.  I tried it under two different usernames and it worked fine
Title: Re: Creating a Working logout link
Post by: General_Sun on July 15, 2007, 05:45:40 AM
I'm sorry, could you post what link that was exactly?

I see forum/index.php?action=logout;sesc=somerandomjumbleoflettersandnumerals
As far as I know the last part is random and created upon logging in. I can't create a link based on that...
Title: Re: Creating a Working logout link
Post by: tick on July 15, 2007, 06:06:09 AM
To be honest I wondered that myself.   But I checked it with two different users and on two different login and cleared everything and it worked.  But that is what I used.
Title: Re: Creating a Working logout link
Post by: fb on July 15, 2007, 06:34:12 AM
Here's what i came up with (works fine in a PHP block)


Quote

global $context, $scripturl;

if ($context['user']['is_logged'])
   echo  '
      <a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">' , $txt[108] , '</a>';

Title: Re: Creating a Working logout link
Post by: General_Sun on July 15, 2007, 02:14:12 PM
Super duper! Thank you a great avalanche!
Title: Re: Creating a Working logout link
Post by: Shane84 on September 15, 2007, 10:57:57 AM
Quote from: Number7 on July 15, 2007, 06:34:12 AM
Here's what i came up with (works fine in a PHP block)


Quote

global $context, $scripturl;

if ($context['user']['is_logged'])
   echo  '
      <a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">' , $txt[108] , '</a>';


That's almost exactly what I was looking for...is there any way to execute that through the sitemap?

Let me explain...I want to eliminate the header all together and use the sitemap as the general navigation, to do this I want to add the logout to the sitemap as well but as we know the session ID makes it difficult.  What I did with this code was insert it into an article and have the sitemap point to it but of course that just makes it a link to a link (redundancy, redundancy).

Perhaps this has been covered already somewhere on here, I'll keep digging but I found this code to be the best help so far.
Title: Re: Creating a Working logout link
Post by: Zetan on September 15, 2007, 11:18:15 AM
hmmm... the Logout can be defined using SSI functions.

http://yoursite.com/ssi_examples.php

and

http://yoursite.com/ssi_examples.shtml


Your forum comes installed with working examples.

See SMF forums for more info on SSI functions.
Title: Re: Creating a Working logout link
Post by: Shane84 on September 15, 2007, 11:53:16 AM
Won't that again give me a link in the sitemap to a link in an article?
Title: Re: Creating a Working logout link
Post by: Shane84 on September 16, 2007, 04:53:21 AM
What I ended up doing is taking some code Bloc posted in another topic and I created another block directly below the sitemap, it's not perfect but it's better than having a link to a link to log out.

php block with no title but using the theme's frame
echo '<a href="index.php?action=logout;sesc='.$context['session_id'].'"><img src="http://www.pogochat.net/Themes/default/images/TPdivider.gif"/><b> Logout</b></a>';