Jump to content

How to restric all pages to logged in users only


charliedg

Recommended Posts

Hello, I want to restric all pages to logged in users only, I found from a past post (I don't know If there is a better way to do it), a hook that works great, you can exclude any page from being blocked, but when users try to reset their lost password (from login form link that sends you to pwreset.php), after they submit their mail, the mail is sent to the user, but the confirmation page where says " Password Reset Requested etc. " is not redirecting correctly and shows me a redirecting error.

I don't know which other file I must exclude or what should I do to work correctly, hope someone can help me.

Thank you!

The hook I'm using is:

<?php
if (!defined("WHMCS"))
   die("This file cannot be accessed directly");

function hook_ForceEveryoneToLogin($vars) {

   $clientID = intval($_SESSION['uid']);
   $adminID = intval($_SESSION['adminid']);

   if ($adminID===0){
       if (!in_array($vars['filename'], array("login","dologin","clientarea","pwreset","register")) && $clientID===0){
           header("Location: login.php");
           exit;
       }
   }

}
add_hook("ClientAreaPage", 1, "hook_ForceEveryoneToLogin");

 

Link to comment
Share on other sites

using the hook in the thread below, I don't seem to be running into any similar issues with Six...

possibly if this were a custom template, you may need to add the password reset templates into the list (though that would need a secondary list), but the big difference between my hook and the one you post is that mine includes index in the list of valid pages and depending on your friendly URL settings, that might solve the issue.

Link to comment
Share on other sites

Hello brian, thanks for your response!

If I include index it works fine, but I also want to restrict homepage, and with index the homepage is accessible, the reason is that I'm creating my website on my main domain, and installed WHMCS on a subfolder, I just want to use it for client area.

Any ideas are welcome, thanks for your help!

Link to comment
Share on other sites

Just a curious question. Why would you want to do that?

I mean it is nice to have the Knowledgebase pages accessible for seo for example.

There is a preset for that in the general settings where you can prevent access to client area for users that are not logged in. Beyond that I think is too much. Its up to you ofcourse i just want to learn your reason and maybe find some use of it.

Link to comment
Share on other sites

On 04/04/2020 at 19:38, charliedg said:

If I include index it works fine, but I also want to restrict homepage, and with index the homepage is accessible, the reason is that I'm creating my website on my main domain, and installed WHMCS on a subfolder, I just want to use it for client area.

I could easily fix it in the hook, but if the homepage is the only issue, then a simpler option might be to alter this through settings.

in the admin area, if you go to setup -> general settings -> other -> Default to Client Area, then that will automatically redirect users from the homepage to the client area - which, if they're not already logged in, will be the login page.

Link to comment
Share on other sites

22 hours ago, weelow said:

I mean it is nice to have the Knowledgebase pages accessible for seo for example. 

Well, the SEO that KB provides is a quite poor. Probably it does more harm than good. It causes duplicated content and multi-language is based on session. In other words it doesn't matter how in how hard you translate articles. Search engines will "see" and index only the default language 😕

Link to comment
Share on other sites

8 hours ago, Kian said:

Well, the SEO that KB provides is a quite poor. Probably it does more harm than good. It causes duplicated content and multi-language is based on session. In other words it doesn't matter how in how hard you translate articles. Search engines will "see" and index only the default language 😕

It doesn't have to be that way.

You can create fixed language urls with fixed language code in the generated URLs

For example:

Yourdomain.com/fr to generate html with fr-Fr

Yourdomain.com/en to generate html with en-GB

Using php routing or .haccess it can be accomplished

You can even add a tag to the header that tells google that the website has different versions of itself with different languages and/or for different locals, hence geo targeting using search engine to display French website for france with euro currency and for Canada with Canadian currency.

So much can be accomplished in this area with time and dedication. I recall that there are free geo hooks available. Take a look at them.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated