• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ General Support (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

redirect on logout event

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
6 posts • Page 1 of 1

Postby fantomasdm » Sat May 03, 2008 3:03 pm

Is possible to redirect to other page after logout event or add callback fuction on logout?
Thanks for help
fantomasdm
New member
 
Posts: 2
Joined: Mon Apr 28, 2008 10:09 pm
Top

Postby moth » Thu May 29, 2008 3:36 pm

I found a kludge that will accomplish this -- it's not pretty, and it doesn't fit well with the rest of the phpfreechat code, but it does work. The idea is to look for where the quit command is passed to Javascript, and hard-code an assignment to window.location within that. So, in data/public/js/pfcclient.js, look for the function handleResponse, and scroll down within that function until you find a snippet of code looking like this:

else if (cmd == "quit")
{
if (resp =="ok")
{
// stop updates
this.updateChat(false);
this.isconnected = false;
this.refresh_loginlogout();
}
}

In this, add a single line assigning your destination URL to window.location:

else if (cmd == "quit")
{
if (resp =="ok")
{
// stop updates
this.updateChat(false);
this.isconnected = false;
this.refresh_loginlogout();
window.location="/your/url/here";
}
}

Now, any time you use /quit to exit, you will be sent to the URL. The redirection happens late enough in the process that the chat does register the quit command. Like I said, it isn't pretty, but it works.

I would very much like to be able to clean this up somehow, in particular by introducing a "redirect" parameter so that I can make the assignment $params["redirect"]="/your/url/here"
in the chat script file, but I haven't been able to figure out how to program a custom parameter. Other posts have asked about custom parameters, too, so I will put my vote in for seeing some documentation on how to do that. The closest I have come is to get rid of the "invalid or obsolete parameter" error by introducing a "var $redirect;" statement in src/pfcglobalconfig.class, but I can't be sure that the value of $params["redirect"] is being assigned to $redirect, and I have no idea how to make sure the value gets passed to the Javascript code, where I would actually need it.

In case you are wondering, my application of this is to use it for password authentication -- the redirect when you logout takes you back to a login page. The login authentication I am using is based on the scripts at http://www.gidforums.com/t-887.html, using the password data from a MySQL database shared also by PunBB.
moth
New member
 
Posts: 4
Joined: Thu May 29, 2008 2:58 pm
Top

Postby moth » Fri May 30, 2008 6:47 am

UPDATE: I kept plugging away at the custom parameter business, and I figured it out. Let me walk you through the steps -- it actually isn't that difficult, and can probably be applied to a lot of other problems:

Step 0: first of all, if you did what I suggested in the previous post, undo it -- remove that one line from data/public/js/pfcclient.js. It was a kludge anyway, and it will just get in the way now.

Step 1: OK, so now it's time to do the real work. Start with src/pfcglobalconfig.php -- you need to add the variable $redirect in the public parameters portion of the file. So where you see the line

var $serverid = '';

add the line

var $redirect = '';

immediately after. This will eliminate the "invalid or obsolete parameter" error, but will not get the value from $params["redirect"].

Step 2: So now it is time to get the value from $params["redirect"] into $redirect. The place to do that is in the constructor function pfcGlobalConfig($params), which you will note takes the $params array as a parameter. This function needs to do some initial setup before it is safe to set the $redirect variable. Look for the code snippet that looks like:

if (!isset($params["data_public_path"]))
$this->data_public_path = dirname(__FILE__)."/../data/public";
else
$this->data_public_path = $params["data_public_path"];

and immediately after it, add the following two lines:

if (isset($params["redirect"]))
$this->redirect = $params["redirect"];

OK, now the value has been transfered from $params["redirect"] to $redirect.

Step 3: Now it is time to use the $redirect variable. Look in the file src/commands/quit.class.php, which is where the /quit command is defined. At the end of that file is the line:

$xml_reponse->script("pfc.handleResponse('quit', 'ok', '');");

This is where the call is made to the handleResponse() function in data/public/js/pfcclient.js, which is where my first post suggested making the modification. Instead, the change will be made in the string which is passed to the script() function in this line. In this file, the $redirect variable from the previous step can be referred to as $c->redirect. So replace this line with the following three lines:

$rs='';
if ($c->redirect!='') $rs='window.location="'.$c->redirect.'";';
$xml_reponse->script("pfc.handleResponse('quit', 'ok', '');".$rs);

This just appends the redirect command immediately after the call to handleResponse(), but includes a check to make sure that the redirect is a nonempty string. (You can probably also include a check that it is a valid URL, bit I didn't do that here.)

Step 4: Now you can make the change in the actual chat script page. Where you set all of your other parameters, include the following line:

$params["redirect"] = "/your/url/here";

You're done!

This does not use a callback, just a string parameter containing the URL, but you can probably modify this in some appropriate way to use a callback instead.
moth
New member
 
Posts: 4
Joined: Thu May 29, 2008 2:58 pm
Top

Postby moth » Fri May 30, 2008 9:09 am

A slight improvement: Instead of the three lines given in Step 3 (starting with "$rs='';"), use the following two lines:

$xml_reponse->script("pfc.handleResponse('quit', 'ok', '');");
if ($c->redirect!='') $xml_reponse->redirect($c->redirect);

The line with the script() method call is now the same as the original, so starting from scratch, just add the second line. This should make it a bit more secure (I think the redirect() method includes a basic URL format check).
moth
New member
 
Posts: 4
Joined: Thu May 29, 2008 2:58 pm
Top

Postby Jaybird » Sun Aug 08, 2010 9:15 pm

been looking for this thread for awhile.. thx moth..
Jaybird
Member
 
Posts: 65
Joined: Mon Jun 28, 2010 7:59 am
Top

Postby waiheke » Tue Sep 14, 2010 6:32 am

Thanks a lot !!

Not only for the code but also for the clear and helpful instructions

:-)
Last edited by waiheke on Tue Sep 14, 2010 6:33 am, edited 1 time in total.
waiheke
Member
 
Posts: 126
Joined: Sun Sep 12, 2010 4:33 pm
Top


Post a reply
6 posts • Page 1 of 1

Return to General Support (v1.x)

Who is online

Users browsing this forum: No registered users and 14 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
cron
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub