Article suggestions
  1. Home
  2. Section: Developer Hub
  3. PHP code snippet to check when a member/user is logged in AND matches another user value (such as a membership plan ID)

PHP code snippet to check when a member/user is logged in AND matches another user value (such as a membership plan ID)

PHP code snippet to check when a member/user is logged in AND matches another user value (such as a membership plan ID)
  • avatar
Written by Chan Nier
Updated on February 19, 2025

 Link: https://support.brilliantdirectories.com/support/solutions/articles/12000095726

The code snippet below will determine when members are logged into a member account AND match additional user criteria.

In this example we check that a user is logged in AND the user matches membership plan with an ID of 1.

Example PHP showing content for logged in membership plan 1 users

<?php
// First, check if the user is logged in
if (user::isUserLogged($_COOKIE)) {

// If logged in, then fetch data of the currently logged-in user
$loggedInUser = getUser($_COOKIE['userid'], $w);

// If the user's subscription ID is 1
if ($loggedInUser['subscription_id'] == 1) {
?>

ENTER TEXT FOR SUBSCRIPTION ID 1

<?php } ?>

Replace "ENTER TEXT FOR SUBSCRIPTION ID 1" with your desired content. This content will be displayed only when a user is logged in.

Example PHP showing content for different logged in users

<?php
// First, check if the user is logged in
if (user::isUserLogged($_COOKIE)) {

    // If logged in, then fetch data of the currently logged-in user
    $loggedInUser = getUser($_COOKIE['userid'], $w);

// If the user's subscription ID is 1
if ($loggedInUser['subscription_id'] == 1) {
?>

ENTER TEXT FOR SUBSCRIPTION ID 1

<?php
}
// If the user's subscription ID is 2
elseif ($loggedInUser['subscription_id'] == 2) {
?>

ENTER TEXT FOR SUBSCRIPTION ID 2

<?php
}
// If the user's subscription ID is 3
elseif ($loggedInUser['subscription_id'] == 3) {
?>

ENTER TEXT FOR SUBSCRIPTION ID 3

<?php
}
// For all other subscription IDs
else {
?>

ENTER TEXT FOR ALL OTHER SUBSCRIPTIONS

<?php
}
}
?>


Thank you for leaving a rating!
Did you find this article helpful?
0 out of 0 people found this article helpful so far
Can't find what you're looking for? Get in touch
How can we help?
Send your question below and we'll get back to you as soon as possible.
Cancel
translation missing: en.kb.default.contact_form_error
×
Thanks for your message!
Thanks for your message!
×