Skip to content

Website Membership

Apart from User Accounts (which handle logging into the CMS Admin), CMS Builder supports member accounts on your public website: visitors can sign up, log in, edit their profile, and view members-only pages.

Front-end logins are handled by the Website Membership plugin. It’s included with modern CMS Builder releases as a required system plugin; if it isn’t in your plugins list, download it from the Website Membership plugin page.

By default, the plugin stores website members in the same accounts table as CMS users, so new sign-ups appear under Admin > User Accounts. It adds a set of Code Generator page types for the membership pages, makes the logged-in visitor available to front-end viewers as $CURRENT_USER, and provides a redirect function for protecting pages.

Admin > Code Generator > Website Membership generates four page types. Save each one under its recommended filename (or choose your own and update the matching URL variable in the plugin file; see Configuration below):

Page typeRecommended filename
Login Pageuser-login.php
Create Accountuser-signup.php
Forgot Passworduser-password-request.php
Edit Profileuser-profile.php

The Forgot Password page handles both the request form and the emailed reset link (the email links back to the same page with a reset code). As with all generated code, adjust the HTML to match your site design.

To require login for a page, add this to the top:

<?php require_once "cmsb/lib/viewer_functions.php"; ?>
<?php if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); } ?>

Visitors who aren’t logged in are sent to the login page and returned to the original page after logging in.

$CURRENT_USER holds the logged-in visitor’s account record (or nothing when logged out), so viewers can vary content by login state or account fields:

<?php if ($CURRENT_USER): ?>
Welcome back, <?php echo htmlencode($CURRENT_USER['username']) ?>!
<?php else: ?>
<a href="/user-login.php">Log in</a> or <a href="/user-signup.php">create an account</a>.
<?php endif ?>

Any field on the accounts table works the same way, such as $CURRENT_USER['premium'] for a checkbox that gates premium content.

To show each member only their own records, load records with the createdBy.* fields (on by default via the loadCreatedBy viewer option) and filter with a where clause on createdByUserNum.

Variables at the top of websiteMembership.php control the page URLs and behavior:

  • WEBSITE_LOGIN_LOGIN_FORM_URL, WEBSITE_LOGIN_SIGNUP_URL, WEBSITE_LOGIN_REMINDER_URL, WEBSITE_LOGIN_PROFILE_URL — locations of the generated pages; update these if you save the pages under different names or paths.
  • WEBSITE_LOGIN_POST_LOGIN_URL / WEBSITE_LOGIN_POST_LOGOFF_URL — where visitors land after logging in or out when no return page is set.
  • WEBSITE_LOGIN_REQUIRED_FIELDS — account fields that must be filled in; logged-in members missing any of them are redirected to the profile page (default: agree_tos, agree_legal).
  • WSM_ACCOUNTS_TABLE — set to a different table name to store website members separately from CMS users; the plugin creates a “Website Users” section for it automatically when specified.
  • WSM_SEPARATE_LOGIN — allows being logged in to the website and the CMS Admin simultaneously as different users.

The plugin installs two email templates, editable under Email Settings > Email Templates:

  • USER-SIGNUP — account details sent after sign-up.
  • USER-PASSWORD-RESET — the password reset link, with #user.email# and #resetUrl# placeholders.
Documents CMS Builder 3.83