Forum

Thread tagged as: Question, Addons

Page visible to members or redirect

I'm new to Perch and have looked at the docs but I can't find an answer to this. Using the Members app, I need a page that is only visible to logged in members. ie:

if (perch_member_logged_in())  = show content
else = redirect to url

or

if (perch_member_has_tag('subscriber')) = show content
else = redirect to url

Thanks

Colin Rood

Colin Rood 0 points

  • 3 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Colin,

You can use PerchSystem::redirect():

// if not logged in, redirect to /another-page
if (!perch_member_logged_in()) {
    PerchSystem::redirect('/another-page');
}

Hi Colin

Welcome to Perch! You can check and redirect to another page if a member is not logged in – NB this must go above anything else on your page template as it uses a header redirect.

    if (!perch_member_logged_in()) {

        PerchSystem::redirect('/path/to/redirect/');

    }

You could make that more complex by adding in a tag check too like if (!perch_member_logged_in() && !perch_member_has_tag('guest'))

Ha ha - snap Hussein!

Perfect - thanks