Check User Subscription Active with User ID

Discussion in 'Customization & add-ons' started by rcstar, Jun 17, 2010.

  1. rcstar

    rcstar aMember Pro Customer

    Joined:
    May 23, 2010
    Messages:
    27
    Is there a way for someone to check if a subscriber is active just by entering their user id?

    Such as, subscriber gives a business their user id to receive a discount. The business accesses our amember site and inputs the user id associated with the account and is able to instantly see if the subscription is active. No private account information is to released, just if the account is active. Is this possible? Is it already implemented?

    Anyone done this before?
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    This is possible for sure. Here is an example in php how you can check is user active or not.

    PHP:
    include "/path/to/amember/config.inc.php";
    $member_id intval($_GET[member_id]);
    $user $db->get_user($member_id);
    if(
    $user[status]==1){
    print 
    "user is active";
    }else{
    print 
    "user is not active";
    }

  3. rcstar

    rcstar aMember Pro Customer

    Joined:
    May 23, 2010
    Messages:
    27
    How can I insert this code into the /amember/templates/index.html file so a visitor can check if a member is active?
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    In smarty to can place php code inside {php}{/php} tags. Also inside aMember template first include is not required.
  5. rcstar

    rcstar aMember Pro Customer

    Joined:
    May 23, 2010
    Messages:
    27
    Where do I place the above code in the index.html file so it is functional?
  6. rcstar

    rcstar aMember Pro Customer

    Joined:
    May 23, 2010
    Messages:
    27
    Better yet, how do I step by step get this to work? Where do I place what code into what file to get this ability on the signup page or index page?

    It must be simpler than this.
  7. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    What exactly you need to do?
  8. rcstar

    rcstar aMember Pro Customer

    Joined:
    May 23, 2010
    Messages:
    27
    I want someone (either a registered member or just a sight visitor) to be able to enter the subscription ID or internal member ID number into a field on a web page and generate whether the user is active or expired. It would be nice to show the expiration date too if that is possible. I just don't know how to implement it.
  9. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Well above example do what you need already, so if you don't know php this is better to ask someone to implement this.
  10. rcstar

    rcstar aMember Pro Customer

    Joined:
    May 23, 2010
    Messages:
    27
    Alright, here is what I'm doing. I've created a php file called check_member_id.php and it contains this:
    <form action="check_member_id_action.php" method="get">
    <p>Check to see if the Membership is Active or Expired by entering the Member ID Number below:</p>
    <p>Member ID Number: <input type="text" name="member_id" /></p>
    <p><input type="submit" /></p>
    </form>


    The check_member_id_action.php contains this:
    <html>
    <body>
    <?php
    include "./config.inc.php";
    $member_id = intval($_GET[member_id]);
    $user = $db->get_user($member_id);
    if($user[status]==1){
    print "user is active";
    }else{
    print "user is not active";
    }
    ?>
    </html>
    </body>


    When I enter a member ID number, the results I get are this:
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /./././amember/check_member_id_action.php:5) in /./././amember/common.inc.php on line 1807
    WARNING: Cannot modify header information - headers already sent by (output started at /./././amember/check_member_id_action.php:5) in line 1651 of file common.inc.php
    user is active


    Why is an error occurring even though I'm getting the proper response from the amember database?
  11. rcstar

    rcstar aMember Pro Customer

    Joined:
    May 23, 2010
    Messages:
    27
    I also added the <?php session_start(); ?> to the top of the php file and now the error reads:
    "WARNING: Cannot modify header information - headers already sent by (output started at /./././amember/check_member_id_action.php:6) in line 1651 of file common.inc.php"
    What else can be done to prevent this now?
  12. rcstar

    rcstar aMember Pro Customer

    Joined:
    May 23, 2010
    Messages:
    27
    Fixed it! I removed the html and body tags and it works!
  13. rcstar

    rcstar aMember Pro Customer

    Joined:
    May 23, 2010
    Messages:
    27
    Now, how do I insert this code into an html file?
  14. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Just make sure that You include config.inc.php before any output or html code so for example:
    PHP:
    <?php
    include "./config.inc.php";
    ?>
    <html>
    <body>
    <?php
    $member_id 
    intval($_GET[member_id]);
    $user $db->get_user($member_id);
    if(
    $user[status]==1){
    print 
    "user is active";
    }else{
    print 
    "user is not active";
    }
    ?>
    </html>
    </body>
  15. bfritton

    bfritton Certified aMember Developer

    Joined:
    Oct 26, 2009
    Messages:
    54
    I improved this a bit (printing user's name, telling the checker if the ID doesn't exist in the DB, etc). You could easily change the name in () to the user's email, etc. We wanted to allow our checkers to verify that the ID number they were given belonged to the person giving it.

    Here it is:

    PHP:
    <?php
    include "./config.inc.php";
    ?>
    <html>
    <title>Check a Member's Account Status</title></head>
    <body>
    <?php
    $member_id 
    intval($_GET[member_id]);
    $user $db->get_user($member_id);
    $namer $db->query("SELECT * from {$db->config[prefix]}members where `member_id` = '$member_id' ");
    $namea mysql_fetch_array($namer,0);
    if (
    $namea != ''){
    $name $namea['name_f'].' '.$namea['name_l'];
    }else{ 
    $name 'Member ID does not exist'; };

    if((
    $user[status]==1) && ($member_id != '')){
    $status 'User with account # '.$member_id.' ('.$name.') is ACTIVE.';
    }elseif((
    $user[status]!==1) && ($member_id != '')){
    $status 'User with account # '.$member_id.' ('.$name.') is <strong>NOT</strong> ACTIVE.';
    }
    ?>
    <h4>Check a Member's account status</h4>
    <form name="check_member_status" action="check_member.php" method="get">
    <p>Input Member ID (Account Number): </p>
    <input type="text" name="member_id" id="member_id" width="30" /><br />
    <input type="submit" value="Check Status" name="Check Status"  />
    </form>
    <?php echo $status?>
    </html>
    </body>
  16. bfritton

    bfritton Certified aMember Developer

    Joined:
    Oct 26, 2009
    Messages:
    54
    Also, I should note... I didn't escape anything in that script so you should escape your entries before submitting the form.

    Edit: Just realized the $GET is secured by the intval operator.

Share This Page