Jump to content
TNG Community

Destination after login


PeterC66

Recommended Posts


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?
 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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??

 

 

Link to comment
Share on other sites

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>..

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

  • 4 weeks later...

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...