PDA

View Full Version : Log out and return to the page you were at


Chen
08 Aug 2001, 15:41
This hack was requested by theflow for God knows how many times.
I'm surprised no one has ever came up with a way to do this, as it's very simple.

Description: This hack lets you place a log out link on any of your pages, and it makes you go back to where you clicked the link from after you have logged out.

Files to edit: member.php.

Templates to add: redirect_logout.

Templates to edit: Any that you want to put the logout link on.

Tested on: vBulletin v2.0.3.

Installation:
1) Open members.php and find

eval("standarderror(\"".gettemplate("error_cookieclear")."\");");
and replace it with

$url = $HTTP_REFERER;
eval("standardredirect(\"".gettemplate("redirect_logout")."\",\"$url\");");

2) Add a template called redirect_logout and put
All cookies cleared. Please wait.
or, as a matter of fact, any other message you want to be displayed.

3) Place
<smallfont><a href="member.php?s=$session[sessionhash]&action=logout">Log Out</a></smallfont>
on any template you want to give the option to log out.

Enjoy this, and please feedback! :)

ThomasP
08 Aug 2001, 16:14
Hi there,

aaah, I see, looks good. I was looking for that quite a time...

Someone came up with that solution for me:

Options -> PHP parsed code

// Register button swapping
if ($bbuserinfo[userid]) {
$registerbutton = "<a href=\"member.php?s=$session[sessionhash]&action=logout\"><img src=\"images/top_logout.gif\" alt=\"Abmelden\" border=\"0\"></a>";
} else {
$registerbutton = "<a href=\"register.php?s=$session[sessionhash]&action=signup\"><img src=\"images/top_register.gif\" alt=\"Als Benutzer registrieren\" border=\"0\"></a>";
}
// end swapping


member.php?action=logout refers to the error_cookieclear
template

cu,
-Tom

theflow
08 Aug 2001, 18:16
I'm confused. I tried this on your site and did not get it to work.

(1) I registered on your site.

(2) I created a new thread for testing:
http://forum.t-cove.com/showthread.php?s=&threadid=37

(3) I attempted to reply to my own message, and at the reply screen, I then logged out as "theflow", got the "cookies are cleared" message. But In attempting to go back to where I was, I reached a "you do not have permission" error, asking me for a username & password. This would make sense if your site requires you to be regsitered to post messages.

But my primary intention (among several) is to be able to have a Registered user logout at the "Reply" compose screen, get a confirmation message that "you are now logged out", and a link to "return to where you were" (as well as second link to "return to startpage" or whatever...)

So this functionality can't be tested on your site if your site requires that a user be regsitered in order to post. ... It's great to see some real effort being put into this, and perhaps you have solved it. I just don't know yet.

Chen
09 Aug 2001, 05:17
Thanks Thomas. :)

TheFlow, you are right, I don't let unregistered users to post on my board. But you can see very clearly on the address bar that you -are- returned to the reply screen.

Chen
09 Aug 2001, 05:52
Ok, I set a demo forum up, just so you could test it. :)
http://forum.t-cove.com/demo/

theflow
09 Aug 2001, 06:37
Originally posted by FireFly
Ok, I set a demo forum up, just so you could test it. :)
http://forum.t-cove.com/demo/

I'll be damned, you sonofa+++++, you did it. That which many others said couldn't be done. Congratulations. Great work.

Here's the thread that confirms it works:
http://forum.t-cove.com/demo/showthread.php?&threadid=1

I requested 3 tweeks, mostly minor I think.... I will post the "enhanced request" :) to vB tomorrow. This is the hack that I have been waiting for for a month, and was growing very frustrated because the logic seemed so clear and consistent -- since vB could hold the URL in one direction --- going from unreg to reg, I couldn't understand why they vB couldn't hold the URL going the other way. As you have proven, it can.

theflow
09 Aug 2001, 06:45
This is repeating here what I wrote at firefly's test site:

I could not understand why people were saying it was hard to hold that URL variable when the existing out-the-box vB currently does that exact thing in the following case:

(see vB thread as reference:
http://www.vbulletin.com/forum/show...&threadid=22185

1. I am unregistered and I go to a thread and hit REPLY to a post.
2. I'm at a Reply screen now. But I Click "register" at top of screen, and go through a Reg process.
3. I get my confirmation screen that I am registered. and there's a link that says "return to where you last were". I click that link.
4. I am redirected to the exact REPLY screen where I started, and now my status shows me logged in with new username.

Why is it that the system and $scriptpath can hold the URL one way but not the other?

-----------
I knew this could be solved, and I am impressed that you did it despite others saying "it's not possible". Good work.

The three tweeks I am looking for:

(1) strip out the pre-fill of the words "Unregistered" at the reply screen

(2) an option would be great such that, upon logout, I get message that cookies cleared (on my site I say "you are now logged out", plus something like this:

------------------------------------------------------------------------------
You are now logged out.

Click here to return to previous screen, or wait a few seconds to return there automatically.

Click here to return to Start page.
-------------------------------------------------------------------------------

(3) A separate request, but kind of related (i will post it later as a separate hack request): Can you find a way to pass the "unregistered name" to the Preview screen and back to the Compose screen if one wants to preview their message first, make a change, then post it? Currently, vB will not hold that username, and unregistered users who use Preview get their name stripped out, often unknowingly. Once they post it's too late because, as unregistered, they cannot edit it...

Again, excellent work firefly!

SirSteve
10 Aug 2001, 14:11
TomasP - can you elaborate a little on where that code goes?

Chen
10 Aug 2001, 15:13
On the left frame, under Styles click on Modify. There click on [fonts/colors/etc] for the style you want this in.
Insert
if ($bbuserinfo[userid]) {
$registerbutton = "<a href=\"member.php?s=$session[sessionhash]&action=logout\"><img src=\"images/top_logout.gif\" alt=\"Abmelden\" border=\"0\"></a>";
} else {
$registerbutton = "<a href=\"register.php?s=$session[sessionhash]&action=signup\"><img src=\"images/top_register.gif\" alt=\"Als Benutzer registrieren\" border=\"0\"></a>";
}
in the field for "PHP parsed code" (By default it's
// This code is PHP4 only:
// ob_start();
// require("yourheader.html");
// $header = ob_get_contents();
// ob_end_clean();
).

Then, write $registerbutton wherever you want the login/logout button to appear. :)

SirSteve
10 Aug 2001, 15:32
Worked flawlessly!

badmeetsevil-
10 Aug 2001, 16:30
Is there anyway to have an outside VB log in script, which does this? I know there's one already out, but me and a bunch of the others requested a "go whatever URL you want" after logging in script. Maybe you can mix the scripts together, and see what you come up with! :-D

Chen
10 Aug 2001, 16:44
First of all, what hack are you talking about?
Also, what happends when you log in using that script? Where does it take you?

theflow
11 Aug 2001, 05:38
Firefly, any progress on the requested tweeks for this hack? I can't use it yet in current state. Thank you.

Chen
11 Aug 2001, 16:54
theflow, you can edit the message at the bottom in the standardredirect template. Use $url for the place you were coming from and $bburl for the forum's index. :)

theflow
11 Aug 2001, 17:04
Originally posted by FireFly
theflow, you can edit the message at the bottom in the standardredirect template. Use $url for the place you were coming from and $bburl for the forum's index. :)

I don't know how to write code, and I am wanting the 2 options to be there, but I also want it to auto-redirect you to where you were after 5 seconds.

I also want to get the "Unregistered" pre-fill text removed from all username entry screens.

I also want to hold the unregistered "screen name" from a preview screen to a Submit action.

Chen
11 Aug 2001, 17:37
To remove Unregistered open sessions.php in your admin folder and replace
$bbuserinfo['username']=iif ($loginusername=="","Unregistered",htmlspecialchars($loginusername));
with
$bbuserinfo['username']=iif ($loginusername=="","",htmlspecialchars($loginusername));

In your standardredirect template replace
<smallfont><a href="$url">Click here if you do not want to wait any longer<br>
(or if your browser does not automatically forward you)</a></smallfont>
with
<smallfont><a href="$url">Click here to come back to where you came from</a><br>
<a href="$bburl">Click here to go to the forum index</a></smallfont>
and that's it. :)

As for holding the new name to the preview screen it's complicated, I'm still trying to figure it all out.

Chen
11 Aug 2001, 18:58
Sorry, I've been trying to find out how to do this for over an hour now, and I just can't do it... I think you'll need a real expert for this one. Sorry. :(