Jump to content

Restrict pages to for logged in users only


Recommended Posts

Hi All,

 

I'm hoping you can help. I've trawled through pages upon pages of documents, community's etc to try and find an answer but I cant find one.

 

Is it possible to restrict our knowledge base page to logged in users only or force them to login? I found this script in a previous post but it redirects all pages to the login page. (which is not good for new/potential customers.

<?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");

Is there something possible i can do to this script to only change it to restrict the knowledge base page?

Link to comment
Share on other sites

<?php

function hook_ForceEveryoneToLogin($vars)
{
	if (!$vars['loggedin'] AND (in_array($vars['templatefile'], array('knowledgebase', 'knowledgebasearticle', 'knowledgebasecat'))))
	{
		header('Location: login.php');
		die();
	}
}

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

 

Edited by Kian
Link to comment
Share on other sites

  • 2 weeks later...

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