Forum

Thread tagged as: Question, Members

Redirect on login

I'm using the members app to create a portal to a page which has access to downloads.

How do I have the user redirected to the downloads page when they submit the login form?

Emily Taylor

Emily Taylor 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

if (perch_member_logged_in()) {
     PerchSystem::redirect('/downloads');
}

Ah ok, brill. Thanks Drew.

Might be good to include that in the docs if not already.

Drew McLellan

Drew McLellan 2638 points
Perch Support

All the pieces are there, I think. Gluing them together is then dependant on the task at hand.

Would this be correct?

<?php
    if (perch_member_logged_in()) {
    PerchSystem::redirect('/downloads');
?>  

<?php
    }else{
        perch_members_login_form(); 
    }
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

In isolation, yes. In practice, you'd need the redirect to happen before you output any of the page body.

Sorry Drew, you are talking to a designer, a total novice developer, I have no idea how to do that, or what it really means.

Is there no dummies guide for how to do it?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Before you output any of the page body, so any HTML for example, you need to do the redirect. There isn't anything else to say about it really, and it's not Perch specific. You can't send a header to do a redirect after you've started outputting stuff.

Ah I see, so really what you are telling me is that I need to put the redirect before any page content e.i. before the <html> in the document.

I have it working perfectly now thank you.