Jump to content

Possible to restrict pages?


Recommended Posts

On 2/20/2018 at 1:11 AM, NameFlag said:

I'm currently working on a new concept for my website, and i'm just wondering if it's possible to restrict access to a custom page unless the person is a member of the group? - which is assigned to them upon ordering the related product?

assuming that you follow this documentation, at the end of your custom page code replace this line:

$ca->setTemplate('{your-template-file-name}');

with this:

$client = Menu::context("client");

/*
Only clients from the specified groups will be able to see content of this page
others will see the restrictive message instead
separate group ids by comma
*/
$allowedGroups = array(1, 2, 4);

# Display page content if client assigned to one of the specified groups
# Replace {your-template-file-name} with your template name
if (in_array($client->groupid, $allowedGroups) || isset($_SESSION['adminid'])){
	$ca->setTemplate('{your-template-file-name}');
}
# Display special message for others
else {
	$ca->setTemplate('content_restricted');
}

now inside your active template directory, create new file called "content_restricted.tpl" and put the following lines inside it:

<div class="alert alert-warning"><p>content of this page only available to specific clients under specific criteria</p></div>

after this, when a client from one of the specified groups access the page, content of that page will be displayed normally (the same for logged in admins), but for visitors or clients from other groups it will display a message indicating that the content of this page is restricted.

it's also possible to redirect user to specific URL instead of displaying the restricted message, for this replace the 

$ca->setTemplate('content_restricted');

with:

header("Location: index.php");
exit;

 

Link to comment
Share on other sites

On 2/21/2018 at 6:37 AM, sentq said:

assuming that you follow this documentation, at the end of your custom page code replace this line:


$ca->setTemplate('{your-template-file-name}');

with this:


$client = Menu::context("client");

/*
Only clients from the specified groups will be able to see content of this page
others will see the restrictive message instead
separate group ids by comma
*/
$allowedGroups = array(1, 2, 4);

# Display page content if client assigned to one of the specified groups
# Replace {your-template-file-name} with your template name
if (in_array($client->groupid, $allowedGroups) || isset($_SESSION['adminid'])){
	$ca->setTemplate('{your-template-file-name}');
}
# Display special message for others
else {
	$ca->setTemplate('content_restricted');
}

now inside your active template directory, create new file called "content_restricted.tpl" and put the following lines inside it:


<div class="alert alert-warning"><p>content of this page only available to specific clients under specific criteria</p></div>

after this, when a client from one of the specified groups access the page, content of that page will be displayed normally (the same for logged in admins), but for visitors or clients from other groups it will display a message indicating that the content of this page is restricted.

it's also possible to redirect user to specific URL instead of displaying the restricted message, for this replace the 


$ca->setTemplate('content_restricted');

with:


header("Location: index.php");
exit;

 

Perfect! Thank you.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • 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