Displaying and Accessing User Data On Your Website

Note that you do not need to use this feature on templates. This is only for accessing user information outside of the pages directly processed and rendered by the program. For templates, we recommend using the caller tag system.

In order to display user information on your website, you will need a basic knowledge of PHP, and the file on which you include this information must be a ".php" file.

Before You Begin

Please open the "member_cp/user_data.php" file and ensure that the $FSP variable on line 5 is using the correct path. If it shows "%%path%%", you need to update it to reflect the full server path to the "/members" folder on your site.

$FSP = "/full/path/to/members";

You can find the correct full path from your admin control panel under "Settings". Simply copy and paste the content of the "Program FSP" option.

Calling the Code

<?php
include "/path/to/members/member_cp/user_data.php";
?>

Checking If a User is Logged In

You can determine if a user is logged in using the following code snippet:

<?php
// User is logged in
if ($logged_in == '1') {
?>
Welcome <?php echo $user['username']; ?> (<a href="/members/logout.php">Logout</a>)
<?php
}
// User is not logged in
else {
?>
Welcome guest (<a href="/members/login.php">Login</a> | <a href="/members/register.php">Register</a>)
<?php
}
?>

Displaying User Information

You can display any field using the following code:

<?php
echo $user['FiElD_NAmE'];
?>

Account Basics

Field NameWhat it DisplaysCodes
usernameMember's username.N/A
emailMember's e-mail address.N/A
statusAccount status.A: Active
E: Expired
C: Paused
joinedDate the user joined.N/A
expiresAccount expiration date.N/A
start_pageCustom start page for this members, if any.N/A
last_loginDate of the user's last login.N/A
loginsTotal number of times this user has logged in.N/A

Custom Fields

Available fields include any custom field that is listed on the admin control panel from "Settings » Custom Fields".

Protected Folder and User Grouping Data

You can determine if a user has access to any user grouping or protected folder by referencing the folder or grouping's ID (the ID can be found from Members » Protected Folders & User Groups).

<?php
echo $user['areas']['gID_HERE'];
?>

The program will return a "1" for "has access" or "0" for "no access". So if you wanted to check if the user has access to protected folder with ID "7", you could do the following:

<?php
// User has access! :)
if ($user['areas']['g7'] == '1') {
?>
Welcome guest (<a href="/members/logout.php">Login</a> | <a href="/members/register.php">Register</a>)
<?php
}
// User does not have access. :(
else {
?>
Welcome guest (<a href="/members/logout.php">Login</a> | <a href="/members/register.php">Register</a>)
<?php
}
?>

Newsletter Subscription Data

You can determine if a user has access to any newsletter by referencing the newsletter's ID (the ID can be found from E-Mailing » Newsletters).

<?php
echo $user['nID_HERE'];
?>

Notice that there is an "n" before the ID. So referencing newsletter with ID 15 would be done as follows:

<?php
echo $user['n15'];
?>

Common Issues

My website disappeared! The screen is blank! HELP!

*slap* Calm yourself man!

This is a simple matter of ensuring the following:

  1. Open the "member_cp/user_data.php" file and ensure that the $FSP variable is set to the correct path. Please see the "Before You Begin" section above.
  2. Ensure that the PHP code that you placed on your page is working correctly. You can test it by removing the code and saving the changes. If the problem disappears, you know that there is a syntax error in your code.

PHP Notice Errors Appear After Including the Code

If after including the "user_data.php" file on your site you see a number of PHP notices, the solution is simply to turn off PHP error reporting. What you are seeing are not errors, but rather notices of undefined variables. PHP does not require that variables be defined, however it will return a "notice" if the your PHP error settings are high enough.

You can turn off error reporting from the "admin/includes/start_load.php" file by adding the following line to the top of the file under the "<?php" line:

error_reporting(0);

If that doesn't work, contact your web hosting provider for help in altering your server settings to suppress PHP errors.