Jump to content
TNG Community

Redirect to index after login - how to


PeterG

Recommended Posts

I've also posted this in the Facebook Group but no answer that works as yet, so thought I'd try here.
 
Essentially I want there to be no access to the site (even the home page) without the person logging in. It is going to be a private family site.  I've installed the latest TNG version.
 
On the forum I found some php to put at the top of the index.php file (i.e. the home page file) to redirect to login.php when the visitor is not logged in. That works fine and I can log in, but then there is no redirect back to the index/home page.  It just sits on the login page and the visitor would have to manually go to the index (home) page. 
 
(If I try to enter other pages when not logged in they automatically go to login without additional code and then redirect back to that page when I log in, e.g. the gallery page. But that doesn't happen when I enter via the home page.)
 
I have tried another forum solution of having two index pages, with the login code copied onto index.php and then a separate index page (index2.php) as the home page, but the same problem remains that there is no redirect back to index (or index2) after logging in. So my question is, how do I get the site to direct the user to login when they first arrive at the index (home) page (so they can't see the index (home) page without logging in) and then have the site redirect to the index (home) page after login?
 
I can't think that I am the only person who ever wanted to do this with a TNG site, so hopefully there's an answer out there.
 
I would be grateful for any help on this!
 
Peter
Link to comment
Share on other sites

As a user, I’d find that frustrating. I have a private site with a number of menu items on the main page. If they click one, they are then required to login to see that page and continue around the site. If I was a user and did that using your approach, I’d be thinking “why am I back on the home page?” Just my 2 cents as feedback.

Phil

Link to comment
Share on other sites

Thanks bhemph and Philip Roy.

I have minimal php skills but I'll see if I can set $_SESSION['destinationpage8'] to the full url of the index page.

Concerning the return to the home page, my intention is only to do that if the visitor had entered the site via the home page,  The way TNG is set up it appears that if someone entered via another page (e.g. if someone had given them a link to that page) they would (without any custom coding) be sent to the login page, and once there and logged in, would automaticlly be sent back to the page through which they had entered the site.  I am not trying to send anyone to the home page who wasn't already trying to go there.

Peter

 

Link to comment
Share on other sites

I just tested my site. I went to the home page, clicked on login, got logged in and redirected back to the home page....so I’m confused sorry. From my perspective you don’t need to code anything, but I may be wrong.

Phil

Link to comment
Share on other sites

5 hours ago, Philip Roy said:

I just tested my site. I went to the home page, clicked on login, got logged in and redirected back to the home page....so I’m confused sorry. From my perspective you don’t need to code anything, but I may be wrong.

Phil

Yeah, but when you first went to the home page you could see its contents, and you weren't immediately told to Log In - you chose to log in.

What Peter G is wanting is that when you go to the home page  you'd immediately be asked to log in, and don't get to see any of the home page until you are logged in. - Like what happens if you try to go to the Admin side of TNG - you can enter the link for admin.php, but you never get to see any of that page as the login screen comes up first.

Roger

Link to comment
Share on other sites

Rob Severijns

Peter,

 

Is editing your .htaccess file an option for you?

There are examples enough on the internet on how to fix that.

search for redirect htaccess amd you'll find solutions.

 

Rob

Link to comment
Share on other sites

Ahh, ok, got it now. I’m away from home at the moment so can’t test this...but thinking out loud. My topmenu file of my template displays different things depending on whether someone is logged in or not. It hides menu items when not logged in. The start of the code is like you see here.

<?php
    	if ($_SESSION['mypersonID'] != "" && $currentuser && $_SESSION['mygedcom'] != "") {
?>        

This checks to see if they are logged in...the ELSE statement for me is to not display as many menu items.

I wonder if your ELSE statement could be a simple automatic redirect to the login page to force them to login? In plain English...

Are they logged in?

Yes - do something

ELSE - redirect to login

Phil

 

Edited by Philip Roy
Link to comment
Share on other sites

Hi all

Thanks for your thoughts.  So far, from a much earlier post on the forum, I've got the following on the home page, to redirect to the login page if not logged in:

if (!$currentuser) {
header('location: login.php');
exit;
}

It's being redirected back to the home page after login that is my issue.  TheKiwi you've summed it up precisely thanks.

I just need the right code to return to home after login, to supplement the above.

Peter

Link to comment
Share on other sites

Peter,
      I put that code in index.php starting as line 3, right after the tng_begin command and upon login I am returned to the index page.  Did you put that code on line 2, before the tng_begin command?

Brent

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