How to retrieve customer info on my own php page

Discussion in 'Customization & add-ons' started by herm1ne, May 7, 2014.

  1. herm1ne

    herm1ne New Member

    Joined:
    May 4, 2014
    Messages:
    5
    In the protected files, I have some php files.
    I want to show customer's name(of course the user currently seeing that page) and mail-address on the page
    Any way to retrieve these info from aMember?

    Thanks in advance!
  2. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
  3. herm1ne

    herm1ne New Member

    Joined:
    May 4, 2014
    Messages:
    5
    Thanks for the info!
  4. raymonda_komar

    raymonda_komar aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    9
    I see that this has been answered loads of time but I am still having problems with it.

    Am_Lite::getInstance()->getUser()

    In using this what code do I use to retrieve the first and last name and their member or user ID to follow what they enter on my php pages. This is quit different from the V3 I am use to where you could use:

    <?php
    session_start();
    print "Welcome " . $_SESSION['_amember_user']['name_f'] . " " . $_SESSION['_amember_user']['name_l'];
    ?></strong></font>
    <br>
    <?php
    $expire = "---"; // not defined
    foreach ($_SESSION['_amember_subscriptions'] as $p){
    if ($p['completed']) {
    $expire = $p['expire_date'];
    }
    }
    print "<br>Your Membership Expires on: <br> " . date('m/d/Y', strtotime($expire));

    $pr_list = $_SESSION['_amember_products'];
    $pr = $pr_list[count($pr_list)-1]['title'];
    print "<br>Type Membership <br> " . $pr;
    ?>

    Any help is greatly appreciated.. I only need to get the first last and user or member ID
  5. raymonda_komar

    raymonda_komar aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    9
    Like this <input type="Hidden" name="member_id" VALUE="<?php echo $member_id ?>" >
  6. raymonda_komar

    raymonda_komar aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    9
    Never mind.. went back to V3
  7. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Anyway I want to answer you here:
    PHP:
    <?php
     
    $user 
    Am_Lite::getInstance()->getUser();
     
    echo 
    $user['name_f'];
    echo 
    $user['name_l'];
    echo 
    $user['user_id'];
     
    $expire Am_Lite::getInstance()->getExpire(Am_Lite::ANY);
     
    echo 
    $expire;
  8. dale_s

    dale_s Member

    Joined:
    Apr 12, 2013
    Messages:
    96
    Great to have found this post. So to insert aMember variables into a custom field of a form, is the following method correct:

    Code:
    <?php
    require_once '/home/mysitepath/amember/library/Am/Lite.php';
    $user = Am_Lite::getInstance()->getUser();
    ?>
    <form method="post" class="form-horizontal KT_tngformerror" id="form1" role="form" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
    <input type="hidden" name="kt_login_email" id="kt_login_email" value="<?php echo $user['email']?>" />
    <input type="hidden" name="kt_login_login" id="kt_login_login" value="<?php echo $user['login']?>" />
    <button type="submit" name="kt_login1" id="kt_login1" value="Insert record" >Get Access Now</button>
    </form>
    Although it seems to work, please let me know if there is anything I have done which is incorrect, or that might cause issues with aMember.
  9. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    @dale_sellers you need to escape data before output it to html eg. htmlentities($user['email']) instead of just $user['email']
    robw likes this.
  10. dale_s

    dale_s Member

    Joined:
    Apr 12, 2013
    Messages:
    96
    Ceasar,

    Thank you for the guidance. It seems to work ways, but I altered code to your suggestion.
  11. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
  12. robw

    robw CGI-Central Partner

    Joined:
    Dec 18, 2007
    Messages:
    287
    Yes, Caesar is correct - never output user input to a page without filtering it (e.g. via htmlentities) otherwise you can leave yourself open to abuse.

    e.g. unfiltered, the following value for $user['login'] would trigger an alert on mouseover...

    Code:
    a@a.com" onmouseover="alert('Bwah ha ha ha!')
  13. rakeshbhai009

    rakeshbhai009 New Member

    Joined:
    Jun 27, 2020
    Messages:
    1
    <?php
    require_once '/home/mysitepath/amember/library/Am/Lite.php';
    $user = Am_Lite::getInstance()->getUser();
    ?>
    <form method="post" class="form-horizontal KT_tngformerror" id="form1" role="form" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
    <input type="hidden" name="kt_login_email" id="kt_login_email" value="<?php echo $user['email']?>" />
    <input type="hidden" name="kt_login_login" id="kt_login_login" value="<?php echo $user['login']?>" />
    <button type="submit" name="kt_login1" id="kt_login1" value="Insert record" >Get Access Now</button>
    </form>

    this code working file sir but How to I update data like name email and pass from custon form how do i do
  14. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    I am afraid Am_Lite API is read only. It is not possible to use it to update user. Customer need to use profile form in aMember to update his account.

Share This Page