Multiple logi and log out pages

By DanMaitland - November 9, 2010 - edited: November 10, 2010

I have a drop down list with English and French and it's called language.

Re: [Dan Maitland] Multiple logi and log out pages

By Jason - November 10, 2010

Hi Dan,

In the example below it checks to see what the value of the language field is for the $CURRENT_USER and sets a redirect url.

NOTE: you may need to change some variable names to match what you have in the database.

// redirect on success
if (@$_SESSION['lastUrl']) { $postLoginUrl = @$_SESSION['lastUrl']; }
else if ($GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL']) {
if($CURRENT_USER['language']=="french"){
$postLoginUrl="/login/login-fr.php";
}
else{
$postLoginUrl="/login/login.php";
}


}
else { $postLoginUrl = thisPageUrl(); }
$redirectUrl = $GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL'];

unset($_SESSION['lastUrl']);
redirectBrowserToURL("$postLoginUrl");
exit;


This code should take care of redirecting after login. It won't take care of redirects to the profile page, logging off, etc.

Making a site bilingual can be a very complicated processes. If you require more help on this, I would suggest sending an email to consulting@interactivetools.com and we can help tailor this code directly to your needs.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason,
In that last piece of code you put up, is $postloginUrl="/login/login-fr" the page that the user will be redirected to once they have logged in? and couldn't this same piece of code work for the logout process?

Re: [Dan Maitland] Multiple logi and log out pages

By Chris - November 11, 2010

Hi Dan,

Yes, you can use the same approach for the "redirect after logoff" logic. Change your _websiteLogin_logoff function to the following: (changes in red)

// remove login cookies
function _websiteLogin_logoff() {
global $CURRENT_USER;

// remove login cookies
$_SESSION = array();
session_destroy();

// redirect after logoff
if($CURRENT_USER['language']=="french"){
$logoffUrl="/index-fr.php";
}
else{
$logoffUrl="/index.php";
}


// unset current user
$CURRENT_USER = false;


//
redirectBrowserToURL($logoffUrl);
exit;

}


The PROFILE_URL isn't used anywhere inside the Website Membership add-on, it's simply there for organization. When you add a link to a profile page, you'll want to use an IF to decide what the URL should be:

<a href="<?php
if($CURRENT_USER['language']=="french"){
echo "/profile_fr.php";
}
else {
echo "/profile.php";
}
?>">Edit Profile</a>


And you're done!

The LOGIN_FORM_URL, SIGNUP_URL, and REMINDER_URL aren't meant to be used for users who are already logged in — when you don't have a user logged in, you won't be able to use the current user's language field to decide what language to show the user, so you'll probably want to use regular links to let users choose their language.

I hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Multiple logi and log out pages

Thank you very much Chris but for some reason it doesnt matter which section which user logs out (english or French) they both redirected to the English section once they log off.

Re: [Dan Maitland] Multiple logi and log out pages

By Jason - November 12, 2010

Hi Dan,

Does the login work correctly or does it always redirect to the English page as well? If you want to fill out a second level support request here:

https://www.interactivetools.com/support/email_support_form.php

I can take a quick look and see what's going on.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
The login works perfectly it's just the piece of code that Chris gave me that doesn't work properly. From looking at it I don't see why it doesn't work, it just redirects back to the english home page no matter whether you french or english.

Re: [Dan Maitland] Multiple logi and log out pages

By Jason - November 16, 2010

Hi Dan,

I found the problem. What was happening in the logoff function is that this code:
// unset current user
$CURRENT_USER = false;


was appearing both before AND after your if statement. This code destroys the $CURRENT_USER variable which is being used in the if statement. This is why is was always redirecting you to the English page. I removed it so that it only appears after the if statement and is seems to work fine now.

Hope this helps.
Jason
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/