Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:38:05+00:00 2026-06-11T17:38:05+00:00

I have 2 snippets (below). The issue is the if statemnt if ($loggedin !=

  • 0

I have 2 snippets (below). The issue is the if statemnt if ($loggedin != NULL){ in the 2nd snippet doesnt pass even if the variable is not null. Its like the $loggedin variable in the 1st snippet doesnt apply to it. If I combine the 2 snippets into 1 they work fine.

Does anyone know how to make 2 snippets ‘talk’ to each other?
(ps, running Revo 2.1.3)

<?php
$loggedin = "";
if (!isset($_SESSION['user_id'])) {
 // redirect to login page
}
else {
$loggedin = "true";
}

2nd:

<?php
if ($loggedin != NULL){
echo  "logged in";
}
else {
echo  "error";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:38:06+00:00Added an answer on June 11, 2026 at 5:38 pm

    First off, you are not passing the $loggedin variable to the second snippet, do this normally with a post or session variable.

    Second, there is an easier way to check, these are straight out of Bob’s guides.:

    There are various methods. One easy method is to use this code:
    
    if ($modx->user->get('username') == '(anonymous)') {
        /* user is not logged in */
    }    
    Here is the official method for seeing if the user is logged in 
    to the current context:
    
    if ($modx->user->hasSessionContext($modx->context->get('key'))) {
        /* user is logged in */
    }    
    If you know the name of the current context (e.g., web), 
    you can use this method. The name of the context is required:
    
    if $modx->user->isAuthenticated('web') {
        /* user is logged in to web context */
    }  
    

    that is if you need to roll your own authentication for some reason. ~ Otherwise, the login/register extra will do all of this for you.

    *UPDATE***
    Two pass variables from one snippet to another in the same resource you can set/get placeholders:

    <?php
    // snippet one
    
    $modx->setPlaceholder('output','Place holder set!');
    
    
    
    <?php
    // snippet two
    
    $myvar = $modx->getPlaceholder('output');
    
    echo 'this is the value of "output": '.$myvar;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this snippet of code below. I want to pass the value of
I'm getting a Variable TMP_1 might not have been initialized error. Here's the snippet:
I have below snippet of code in which TestClass is extending jPanel which is
//I have created below snippet to let the sensor to be detected. -(void)addProximitySensorControl {
I have a code snippet as below <CheckBox Name=cb Margin=1,2,1,0 IsChecked={Binding Path=IsManager} IsEnabled=True/> Consider
I have below code snippet SimpleDateFormat dateFormat = new SimpleDateFormat( yyyy-MM-dd hh:mm:ss.SSS); String processedContentDate=2012-04-10
I have a script snippet looks like below: <ItemGroup> <files Include=*.txt></files> </ItemGroup> <Message Text=@(files)>
htmlparser.Parser, I have the snippet of html(see below) and i need to get the
I have the following snippet in my pom.xml (Full pom attached below which can
Below is the snippet of my code. I have a JTable. I have extended

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.