Forum

Thread tagged as: Question, Problem, Members

Help with Perch Members

Hi, I've been up and down the documentation for Perch Members, but it's so scarce that I cannot seem to get where I want to go. I love Perch, and have a good understanding of code -I'm just missing something.

I want to set up members for my website, each with their own secure dashboard that can only be accessed by them. I know this can be done but I can't figure it out. Do I implement it using member tags? Or do I implement it using resource buckets? Both? And really the big question is HOW? Right now I have a member tag wrapped around a whole page, but it can still be accessed by anyone, even without logging in.

Any help would be greatly appreciated.

Greg Stone

Greg Stone 0 points

  • 6 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

There's pages and pages of members documentation starting here: https://docs.grabaperch.com/addons/members/

If you need additional help then we really need to see your code, so we can see where you have got to.

Thanks for getting back to me. Yeah, I've been through the docs. It doesn't have much to say especially for troubleshooting.

On my server I have a folder named members with the template files (mysite.com/members), and inside of the members folder I have a folder titled "test (mysite.com/members/test) with my own html. What do I have to do to get the "test" folder redirected for a password if not logged in? I have a test member tagged as test thinking it wouldn't let someone see this the test page, but in fact anyone can see it if they know the link.

As for my code, my index.php file in the test folder looks like this:

<?php include('../perch/runtime.php');?>
<?php if (perch_member_has_tag('test')) {
--my html content here--   
}; 
?>

Thanks for your help.

Drew McLellan

Drew McLellan 2638 points
Perch Support

if (!perch_member_has_tag('test')) {
    PerchSystem::redirect('/login');
}

Hi, I tried inserting the redirect php but the webpage is still able to be accessed by anyone with the link and it doesn't redirect to login. Here's the code variations I tried.

  1. <?php include('../perch/runtime.php');?>
    <?php if (!perch_member_has_tag('test')) {
        PerchSystem::redirect('/login');
    }; 
    ?>
    
    --My HTML content here--
    
<?php include('../perch/runtime.php');?>
<?php if (!perch_member_has_tag('test')) {
    PerchSystem::redirect('/login');

--My HTML content here--

}; 
?>


Any thoughts?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What happens? Are you using Perch 2.8.4.?

Thank you. With your support I was able to figure out what I was doing wrong.

One more question. What is the best way on the "index.php" login file, after a user logs in, to redirect them immediately to their own page using member tags. I keep getting a syntax error. I can't figure out what I'm doing wrong.

Here's my code for the index.php login file.

<body>

    <div>

        <div>

        <?php 
            if (perch_member_logged_in()) {
                echo '<div class="welcome"><h1>Hey, '.perch_member_get('first_name').'!</h1></div>';
            }else{
                echo '<div class="header"><img src="https://champkiddesign.com/images/logo_black.png"/></div>';
                echo '<div class="signin"><h1>ChampKid Design</h1><p>Customer Dashboard <sub>BETA</sub></p></div>';
                echo '<p>Sign into Your Account</p>';
            }
        ?>

        </div>

         <?php if (!perch_member_has_tag('userone')) {
            PerchSystem::redirect('userone.html');
        ?>

         <?php if (!perch_member_has_tag('usertwo')) {
            PerchSystem::redirect('usertwo.html');
        ?>



        <nav>
            <?php
                if (perch_member_logged_in()) {
            ?>  

                <ul>
                    <li><a href="profile.php">Edit profile</a></li>
                    <li><a href="logout.php">Log out</a></li>
                </ul>

            <?php
                }else{
                    perch_members_login_form(); 
                }
            ?>
        </nav>  
    </div>

    <?php perch_get_javascript(); ?>
</body>
</html>

Thanks.

Greg Stone said:

Thank you. With your support I was able to figure out what I was doing wrong.

One more question. What is the best way on the "index.php" login file, after a user logs in, to redirect them immediately to their own page using member tags. I keep getting a syntax error. I can't figure out what I'm doing wrong.

Here's my code for the index.php login file.

<body>
  
  <div>
  
      <div>

      <?php 
          if (perch_member_logged_in()) {
              echo '<div class="welcome"><h1>Hey, '.perch_member_get('first_name').'!</h1></div>'; // <===== Your outputting html here, redirect will fail.
          }else{
               echo '<div class="header"><img src="https://champkiddesign.com/images/logo_black.png"/></div>';
              echo '<div class="signin"><h1>ChampKid Design</h1><p>Customer Dashboard <sub>BETA</sub></p></div>';
              echo '<p>Sign into Your Account</p>';
          }
      ?>

      </div>
       
        <?php if (!perch_member_has_tag('userone')) {
           PerchSystem::redirect('userone.html');} // <===== } was missing
       ?>
       
        <?php if (!perch_member_has_tag('usertwo')) {
           PerchSystem::redirect('usertwo.html');} // <===== } was missing
       ?>
       
       
      
      <nav>
          <?php
              if (perch_member_logged_in()) {
          ?>  
           
              <ul>
                  <li><a href="profile.php">Edit profile</a></li>
                  <li><a href="logout.php">Log out</a></li>
              </ul>

          <?php
              }else{
                  perch_members_login_form(); 
              }
          ?>
      </nav>  
  </div>
  
   <?php perch_get_javascript(); ?>
</body>
</html>

Thanks.

You were missing (2) curly brackets on your if statements...

But your also using

PerchSystem::redirect()

after your page has already output some html, so you'll get a warning saying headers already sent.

You'll want to place the redirect near top of page before any html is output otherwise it will continue to fail.

I HAVE PLACED COMMENTS IN QUOTED CODE