Custom Error Messages based on membership level?

Discussion in 'Customization & add-ons' started by jcary, Apr 12, 2010.

  1. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Hi,

    I was wondering how this is possible... I currently have 3 levels of membership (Bronze, Silver, Gold...).

    I have links to all three protected areas in the members area, visible to all no matter what level you are.

    So if a Bronze member clicks on the Silver link, he is naturally directed to the login page alerting him that he does not have access to this page.

    Same thing for the Silver who clicks on the Gold link.

    Is it possible to customize the error page or message to be specific to the link.

    For example, when the Bronze clicks on Silver, I want to list all the reasons to upgrade to Silver, etc.

    What file can I begin to modify to achieve this?

    Thanks a lot.

    Josh
  2. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    Not likely.

    You'd need some custom modifications for that to happen.
  3. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Josh you need to customize /amember/plugins/protect/php_include/check.inc.php and possible show different template depending on products user have.
  4. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    OK, so how about this solution...

    Since I can already call the member's name by using

    PHP:
    <?php echo ($_SESSION[_amember_user][name_f]); ?>
    Is there a similar php function what will achieve the following:

    PHP:
    if ( amember user does not have product_id 6 ) {

        echo 
    "<a href=\"this.html\">";
        
    } else {

        echo 
    "a href=\"that.html\">";
        
    }
    Thanks.

    -Josh
  5. erwinvdb

    erwinvdb aMember Pro Customer

    Joined:
    Aug 30, 2007
    Messages:
    264
    It's in the documentation:
    Code:
    session_start();
    $need_one_from = array(3,4); 
    if (array_intersect($need_one_from, $_SESSION['_amember_product_ids'])){
       print "User is subscribed to product #3 or product #4";
    } else {
       print "User is not subscribed nor to product #3, nor to product #4";
    }
  6. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    That's perfect, erwin!

    Thanks for spelling it out... works flawlessly.

    -Josh
  7. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Additional Question regarding this code and specifically the "session_start();" part...

    Is it mandatory for the session_start(); part to be at the very top of the php page, or is it ok to simply place it within the code on the page when I need it?

    I ask because it's going to go in a uniform menu bar and is not practical for me to go in and add the session_start(); code to the top of ALL php pages.

    Is there something I need to consider if I place it in the menu code?

    Thanks.
  8. grantswaim

    grantswaim New Member

    Joined:
    Mar 16, 2008
    Messages:
    109
    You did not indicate which platform you are using to deliver the premium content. If you are using WordPress, this plug-in, under development by aMember, will do this. You make a post and define it as an aMember error message with a custom field. Then you can assign the custom written error message to any of the protection levels.

    Good Luck!
  9. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Hey Grant,

    Thanks for that link... I am not, however, using Wordpress.

    This code will go on my php file on my website.

    Thanks.
  10. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    yes it should be at the top of the page. If there will be any html or php output before session_start() warning will be generated by php

Share This Page