Jump to content
TNG Community
PeterC66

Destination after login

Recommended Posts

PeterC66


I am using TNG v13 integrated with WordPress via the Kloosterman method.  After many years of not, I have recently switched for copyright reasons to requiring TNG users to login and all seems to work OK on my WAMP.
 
My issue is that users may arrive at a TNG page from outside TNG (eg because of a link in WordPress), and the login does not remember where they were trying to get to and instead sends them after logging in to a home page.
 
I have chased the issue down to session variable destinationpage8. At some point in the past (before at least v10.12) the line where the session variable is set (line 6 in login.php) was commented out so it now reads:
 

//$_SESSION['destinationpage8'] = $HTTP_REFERER;


 I have done myself a small mod to un-comment this line and I seem to have solved my issue.
 
On checking with Darrin he says he commented it out some time ago because it caused a problem for someone, but he can't remember what that might have been. 

As I seem to be the first to raise it for a long time it may not be a major issue and I am happy to live with my little mod. But does anyone have any comments on reinstating that line in TNG generally?
 

Share this post


Link to post
Share on other sites
klooster

Hi Peter, I commented out as you suggested, but after login or logout from a different page I am still redirected to the homepage??

Share this post


Link to post
Share on other sites
PeterC66

Hi Cees,  What I have done is un-comment it (not an English word - sorry!) -

ie replace 

//$_SESSION['destinationpage8'] = $HTTP_REFERER;

by 

$_SESSION['destinationpage8'] = $HTTP_REFERER;

Otherwise, I think destinationpage8 never gets set.  There is lots of code that refers to it.

By the way, although I mentioned WordPress I think this is a pure TNG issue that applies to all of us. But maybe only someone with a site that is not pure TNG would notice it.

Share this post


Link to post
Share on other sites
klooster

Well that’s what I did, I uncommented it and it still directs me to the homepage.

PS: and cleared my cache ofcourse

Share this post


Link to post
Share on other sites
PeterC66

Apologies all. I have confused myself by having two almost identical sites, jumping at an easy answer, and working late at night.  I think the behaviour with my little mod I am seeing is that after login it returns to the page that triggered it, which is probably what was intended by the code ie HTTP_REFERER. This is not what I want, and some warn against it eg  I wouldn't recommend using HTTP_REFERER.

I shall try to explore things more, but you can ignore what I said before.

Share this post


Link to post
Share on other sites
PeterC66

I have found a way to do this, but it needs testing more. Essentially we capture the $REQUEST_URI (the URL we were trying to get to) before we call login.php. It is one extra line of code and here is my little mod version (note the original line has several tabs):

%target:checklogin.php%
%location:%
					header( "Location: " . getURL("login", 0));
%end:%
%insert:before%
					$_SESSION['destinationpage8'] = $REQUEST_URI; // Amended by Destination after Login Mod //
%end:%

If anyone fancies trying it I would be grateful for feedback.

Share this post


Link to post
Share on other sites
Ken Roy

I know it is a problem in TNG if you use multiple tabs to the same TNG site.  Login does not always return you to the page you requested a login from.  I am travelling today, so I will test it tomorrow when I am back home

Share this post


Link to post
Share on other sites
klooster

Tested it Peter, crashed TNG, 505 error

Share this post


Link to post
Share on other sites
RickM

Hi Peter

Initial testing here seems to be fine..

I have a link sat in another app I use, which directs to a family member. I do get redirected to that page after login.

I will test some more, as best I can..

Clever idea..

FURTHER TESTING..

Even commenting out the line it seems I get redirected to the page I was requesting once I have logged in.. Hmm I wonder if this might be a Theme / Plugin..

Do you have a test login that I could use (PM the details if you prefer) along with a couple of links??

 

 

Share this post


Link to post
Share on other sites
RickM
8 hours ago, klooster said:

Tested it Peter, crashed TNG, 505 error

Cees

That could be related to the link you are clicking on I found this that explains the issue
https://bobcares.com/blog/505-http-version-not-supported/

Oh and BTW, your site loaded quite well today what did you do?? Or maybe our Internet suddenly got better <SMILE>..

 

 

Share this post


Link to post
Share on other sites
klooster

Tested it again Peter:, see below:

 

***********************************************

elseif( $requirelogin ) {
                if(!substr_count( $_SERVER['SCRIPT_NAME'], "/index." ) && !substr_count( $_SERVER['SCRIPT_NAME'], "/ajx_tnginstall.php" )) {

                    // insert mod line return login
                    $_SESSION['destinationpage8'] = $REQUEST_URI;
                    //end mod line return login

                    header( "Location: " . getURL("login", 0));
                    exit;

**********************************************

Result: not working, no 505 errror anymore, but it still directs me back to my home page!

Share this post


Link to post
Share on other sites
PeterC66

Hi Cees

Thanks for testing this. I cannot claim to understand much about this area of TNG, but looking at the code in my version of checklogin.php I see that this new bit of code triggers just before loading the login.php and only when:

TNG requires logging in -

elseif( $requirelogin ) {


and 

$admin_login is not set  -

if( $admin_login ) {..} elseif( $requirelogin ) {


and

something about not being called from any index.php file -

if(!substr_count( $_SERVER['SCRIPT_NAME'], "/index." ) && !substr_count( $_SERVER['SCRIPT_NAME'], "/ajx_tnginstall.php" )) {


and

something about the session
  

 if( isset( $_SESSION['logged_in'] ) && $_SESSION['session_rp'] == $rootpath && (!$admin_login || ($_SESSION['allow_admin'] && $currentuser))) {} else {

 

There is also a way the system might not get there if a cookie is set

if( isset( $_COOKIE[$usercookiename] ) ) {

Could any of these conditions be affecting your situation?

Share this post


Link to post
Share on other sites
klooster

Which TNG version do you  have Peter?

 I am using V 13.01

Share this post


Link to post
Share on other sites
PeterC66

Cees I am on v13.1.

 One other thought.  My new change does require that that line I erroneously suggested un-commenting in login.php is back to being commented out.

//$_SESSION['destinationpage8'] = $HTTP_REFERER;

 

Share this post


Link to post
Share on other sites
klooster

Yes I commented it out. 

I mistyped my TNG version, I am on v13.1 also

Share this post


Link to post
Share on other sites
PeterC66

After some more testing, my little change seems to work as I want except for one situation.  If someone goes specifically to the login page then after login they are taken back to the same login page. With my limited knowledge, I have not found a way around that yet, but their logging in has still worked.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×