TinyPortal

Development => Support => Topic started by: Stroopy on January 22, 2009, 07:35:46 PM

Title: Self made logout button in a PHP block help.
Post by: Stroopy on January 22, 2009, 07:35:46 PM
Hey all,

I've edited my layout and all so the bottons that are on top are gone.
Now the only problem I have is that there's no logout botton.

Can someone please tell me how to make one?

I've tried to make a link that goes to http://(website).com/index.php?action=logout but then I get Session verification failed. Please try logging out and back in again, and then try again.

Please help.
Title: Re: Self made logout button in a PHP block help.
Post by: G6Cad on January 22, 2009, 07:59:04 PM
Please read the Posting Guidelines.html (http://www.tinyportal.net/index.php/topic,581)
Title: Re: Self made logout button in a PHP block help.
Post by: IchBin on January 22, 2009, 08:25:19 PM
You get a session verification error because the session ID is passed in the URL when you logout. If you look at the logout button that you took out, you can see how the ID is passed into the URL.
Title: Re: Self made logout button in a PHP block help.
Post by: Stroopy on January 22, 2009, 08:56:09 PM
Quote from: IchBinâ„¢ on January 22, 2009, 08:25:19 PM
You get a session verification error because the session ID is passed in the URL when you logout. If you look at the logout button that you took out, you can see how the ID is passed into the URL.

I kept trying that but I just cant work it out how it work.
What I want is a text hyperlink that logs you out when you click it in a PHP block but I cant get it. :(
Title: Re: Self made logout button in a PHP block help.
Post by: IchBin on January 22, 2009, 09:08:17 PM
Show me how you are passing the session id into the link in your code then, so I can show you whats wrong.
Title: Re: Self made logout button in a PHP block help.
Post by: Stroopy on January 22, 2009, 09:15:47 PM
Quote from: IchBinâ„¢ on January 22, 2009, 09:08:17 PM
Show me how you are passing the session id into the link in your code then, so I can show you whats wrong.

<a href="(website).com/index.php?action=logout;sesc=session_id">Logout</a>
Thats the best I can get, I also tried too edit the normal logout PHP code but without luck.
Title: Re: Self made logout button in a PHP block help.
Post by: JPDeni on January 22, 2009, 11:53:08 PM

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


Be sure that you've included $scripturl and $context in your global command at the beginning of your code.
Title: Re: Self made logout button in a PHP block help.
Post by: IchBin on January 23, 2009, 01:38:34 AM
Quote from: Stroopy on January 22, 2009, 09:15:47 PM
Quote from: IchBinâ„¢ on January 22, 2009, 09:08:17 PM
Show me how you are passing the session id into the link in your code then, so I can show you whats wrong.

<a href="(website).com/index.php?action=logout;sesc=session_id">Logout</a>
Thats the best I can get, I also tried too edit the normal logout PHP code but without luck.

As you can see by Deni's code you were not including the actual session ID. The word session_id does not hold any value. If you hover your mouse over the link after using Deni's code you will see there is an actual ID number that is like 40 characters long that is necessary to login and logout.

Thanks Deni! :up:
Title: Re: Self made logout button in a PHP block help.
Post by: JPDeni on January 23, 2009, 02:07:08 AM
:) I knew right where it was and happened to have an index.template.php file open on my computer. It was just a matter of doing a search for the text and copying it. :)
Title: Re: Self made logout button in a PHP block help.
Post by: Prophecyrising on May 25, 2010, 11:32:15 PM
How can you do this using tpmenu link?
I've tried "index.php?action=logout;sesc=session_id" (no quotes), but I get "Session verification failed. Please try logging out and back in again, and then try again."
I can't use "', $scripturl, '?action=logout;sesc=', $context['session_id'], '" either, or I get mysql fits.
Any suggestions?

TinyPortal 1.0 beta 5-1
SMF 2.0 RC3
Title: Re: Self made logout button in a PHP block help.
Post by: IchBin on May 26, 2010, 12:21:59 AM
That's because SMF2's code has changed. You'll probably have to do something like this:

"', $scripturl,'?action=logout;', $context['session_var'] ,'=', $context['session_id'],'"
Title: Re: Self made logout button in a PHP block help.
Post by: Prophecyrising on May 26, 2010, 06:18:44 AM
That's a no go. If I enter that via the menu manager I get "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''?action=logout;', $context['session_var'] ,'=', $context['session_id'],'"' WHER' at line 1".
I've even tried putting it in manually in mysql.. it goes in but the link does nothing but go to the main page.
The mouse over just comes up "http://mywebsite.com/index.php". No session info at all.

I'm guessing there's no way to do this within the tpmenu structure.
Title: Re: Self made logout button in a PHP block help.
Post by: IchBin on May 26, 2010, 06:24:07 PM
So are you trying to do it in the menu manager or a php block like the title of the topic says?
Title: Re: Self made logout button in a PHP block help.
Post by: TankGirl on May 28, 2010, 01:35:56 AM
I ended up making a PHP article page with logout confirmation. Like this.
$logoutlink = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">[LOGOUT]</a>';
echo "<center><font size=3>Please confirm logout....<br>";
echo $logoutlink;
echo "</font></center>";


Then I made a link in menu manager to link to that article. But I would prefer to find a cleaner way of adding a logout link the menu manager menu. :crazy2:
Title: Re: Self made logout button in a PHP block help.
Post by: Lesmond on May 28, 2010, 05:44:44 AM
Quote from: TankGirl on May 28, 2010, 01:35:56 AM
I ended up making a PHP article page with logout confirmation. Like this.
$logoutlink = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">[LOGOUT]</a>';
echo "<center><font size=3>Please confirm logout....<br>";
echo $logoutlink;
echo "</font></center>";


Then I made a link in menu manager to link to that article. But I would prefer to find a cleaner way of adding a logout link the menu manager menu. :crazy2:

You could just place that code into a php block, tested and seems to work fine on our test site!
Title: Re: Self made logout button in a PHP block help.
Post by: TankGirl on May 28, 2010, 06:13:41 AM
Then I end up writing the whole damn nav block.. a dozen links that always change... the menu manager at least makes this easy and modular.
Oh and i have seperate nav blocks for guest and members.
Especially with articles.. just a drop menu boom link done... lol
I guess i'll just stick to my way until tinyportal decides to add logout option to menus...
Title: Re: Self made logout button in a PHP block help.
Post by: IchBin on May 28, 2010, 04:04:54 PM
Well there's no way to pass in any type of variables in the menu manager. Sorry.