How can I password protect a page

3 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 4, 2016   (RSS)

By JeffC - April 26, 2016

I am using the membership plugin. I have two pages that I would like to make accessible to members only.

I my navigation I have used this to hide the links from anyone who is not logged in:

<?php if ($CURRENT_USER): ?>
<li><a href="/library-list.php" title="Library">Library</a></li>
<li><a href="/documents-list.php" title="Documents">Documents</a></li>
<?php endif ?>

The above stops a non-member from seeing the link and clicking on it. However, it doesn't stop a non-member from going directly to the page if they know the full url.  Eg www.domainname.co.uk/library-list.php is accessible to anyone.

How would I create a warning that says something like "you need to be a member to access this page" when someone attempts to access the page?

Thanks

Jeff

By Damon - April 27, 2016

Hi Jeff,

For the library-list.php page, you could add this code to display the message for users that aren't logged in:

<?php if (!$CURRENT_USER): ?>
    You need to be a member to access this page.
<?php endif ?>

You could also add a link to login or register etc.

Make sure all the content on the page that should be only visible to users that are logged in uses this code:

<?php if ($CURRENT_USER): ?>
Only logged in users will be able to see this content
<?php endif ?>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/