redirection based on user (if / not logged in)

Discussion in 'Setting-up protection' started by bdmc, Apr 23, 2012.

  1. bdmc

    bdmc New Member

    Joined:
    Mar 23, 2012
    Messages:
    20
    Hello,

    I do not want to protect the entire page. But instead if the user is not logged in, he can then go to any section of the website.

    If the user is already logged in, he is still on the same page (main page), but access links are not the same.

    Exemple: user (not logged in), want to go to the "Articles" page. This is a free section with limited content. But if the user is logged in and want to go to the "Articles" page, he can view other articles that were not viewable if the same user was not logged in. If he is logged in, the link to articles.php becomes then articles-ac.php which allows the user to see viewable content.

    Code:
    <?php
    require_once '/root access/amember/library/Am/Lite.php'; // Adjust path to aMember folder
        if (!Am_Lite::getInstance()->isLoggedIn()) {
            header("Location: http://mysite.com/amember/login?amember_redirect_url=http://mysite.com/article-ac.php");
        exit;
          }
    ?>
    This code only protects the entire page and directs the user to the login area. I have not found a way to change it as I explained in the beginning.
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    You can use the same code, but change redirect part.
    For example:
    PHP:
     if (!Am_Lite::getInstance()->isLoggedIn()) {
    // user is not logged in show content available for all. 
    }else{
    // user is  logged in show content available for logged in users. 
    }

Share This Page