Forum

Thread tagged as: Question, Members

Members area login form

Hi

I've just recently added a members area to a clients site but they are wanting to have the login form on each page of the site. I've done this and it redirects the user to the dashboard page, however i would still like the user to be able to navigate the rest of the site when logged in. Currently when logged in and they go to another page on the site which isn't in the members area they are redirected back to the dashboard. Is there a piece of code which can be added to the code below which I could use that will redirect a user to the dashboard on successful log in but after that they can navigate the site freely, without being redirected back to the dashboard?

Here's the code I have at the top of each page on the site

<?php if (!defined('PERCH_RUNWAY')) include($_SERVER['DOCUMENT_ROOT'].'/admin/runtime.php'); ?>

<?php 
    if (perch_member_logged_in()) {
        PerchSystem::redirect('/members/dashboard.php');    
    }
?>

Thanks for any help.

Peter Meenagh

Peter Meenagh 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

At the moment your code is saying "if the member is logged in redirect to the Dashboard".

Presumably you want to check to see if the member is not logged in on secure pages and redirect to the login page. Eg:

<?php 
    if (!perch_member_logged_in()) {
        PerchSystem::redirect('/members/login');    
    }
?>

Thanks Rachel but the login form would be on each page throughout the website which pop ups in a modal window. I still want a user to be redirected to the dashboard in the members area on login. For example if they login through the homepage they would be redirected to the dashboard, but I also want them to be able to go back to the homepage (while logged in) without being redirected to the dashboard again.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to use

PerchSystem::redirect('/members/dashboard.php?r=/place/to/go/next');   

Hi Drew

Apologies for the late reply. Where does this go? I've put it on the homepage like below but whenever I go to the homepage it still redirects to the dashboard.

<?php if (!defined('PERCH_RUNWAY')) include($_SERVER['DOCUMENT_ROOT'].'/admin/runtime.php'); ?>
<?php 
    if (perch_member_logged_in()) {
        PerchSystem::redirect('/members/dashboard.php?r=/index.php');   
    }
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Use it at the point you want to send someone out to the login page.