Jump to content
TNG Community

done - creating a new page only for logged in users


JPB

Recommended Posts

Hi,

I need your help please. I want to integrate a new page that should be accessible only for logged in users.

I have built the page with the historytemplate.php, it works fine. Also the integration in the menu bar worked well.

What code do I need to integrate at the top of the page that checks if the visitor is logged in? If he is NOT logged in, he should be redirected to the login page.

Thanks and have a nice weekend

Jürgen

-----------------------

I think I have found my mistake. I had inserted the code:

if (!$currentuser && !$_SESSION['currentuser']) {header('location: ../login.php'); exit;}

before

include( "../tng_begin.php");

But it must be inserted BELOW this line, then everything works as desired.

Learning by doing ...😁

Jürgen

Edited by JPB
done
Link to comment
Share on other sites

Michel KIRSCH
On 3/6/2021 at 8:28 AM, JPB said:

What code do I need to integrate

Hi Jürgen,

in the historytemplate.php file, these lines :

//1a: If you want to skip the login check when displaying this page, remove the comment marks from this line:
//$nologin = 1;


indicates that you have nothing to do/integrate to check if a user is connected...
Why must you insert your own code?

Michel

Link to comment
Share on other sites

vor 1 Minute schrieb Michel KIRSCH:

Why must you insert your own code?

... because this code has no function (at least for me?).

Link to comment
Share on other sites

1 hour ago, Michel KIRSCH said:

Why must you insert your own code?

Could it be because Jurgen's site

normally is 'public' and doesn't require a login?  Then the $nologin might have no effect.  Just a thought.

Link to comment
Share on other sites

2 hours ago, Michel KIRSCH said:

in the historytemplate.php file, these lines :

//1a: If you want to skip the login check when displaying this page, remove the comment marks from this line:
//$nologin = 1; 


indicates that you have nothing to do/integrate to check if a user is connected...

The $nologin check was added to the historytemplate.php in TNG v12 to bypass the login check for users who require login on their sites and wanted to allow certain pages to be available to anonymous users.

What Jürgen wanted was the opposite - restrict a page to logged in users on a site that does not require login

Link to comment
Share on other sites

The wiki article on $nologin_option should be updated to provide a better explanation.  The previous version of the historytemplate.php allowed users to comment out the call to checklogin.php if your site required login and you wanted to make certain pages available without requiring the login

 

Link to comment
Share on other sites

Michel KIRSCH
1 minute ago, Ken Roy said:

if your site required login and you wanted to make certain pages available without requiring the login

Ah ! It's well what i've thinked...

Thx Ken

Link to comment
Share on other sites

vor 13 Stunden schrieb Ken Roy:

if your site required login and you wanted to make certain pages available without requiring the login

thank you all.

I actually assumed a different function. This command releases something, but I thought it would prevent something.

Learning by listening ... 🤣

Jürgen

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