redirect url with user id added

Discussion in 'aMember Pro v.4' started by rance, Jan 28, 2013.

  1. rance

    rance aMember Pro Customer

    Joined:
    Dec 1, 2012
    Messages:
    42
    In my redirect after login, I need to add the user name at the end. www.example.com/.../userid

    I have seen a bit about redirects here, but have not seen how to solve for this.
    please help.
  2. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    Can you explain why you need this- redirecting to another site?
    Did you try %user.login% (not sure if it will work... I dont think amember is set up to handle this)

    David
  3. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Create redirect script for example redirect.php:
    PHP:
    <?php 
    include "/amember/library/Am/Lite.php";
    $user Am_Lite::getInstance()->getUser();
    if(!
    $user
     
    header('Location: /amember/login');
    else
      
    header('Location: /url/'.$user['user_id']);
    ?>

    Then in amember CP -> Setup -> Login -> Redirect After login set to fixed and specify url of your redirect.php
  4. rance

    rance aMember Pro Customer

    Joined:
    Dec 1, 2012
    Messages:
    42
    OK, I really tried to do this. Think I am missing something simple. 2 quick questions.

    1. Where specifically should I put the file.
    2. How specially do I access it.

    Example of what did not work:
    I created the file redirtest.php with the above and saved it at /amember/

    set the redirect to url/amember/redirtest.php
    I get a 404 error

    Rance
  5. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Edit .htaccess file inside aMember folder and add one line to it:
    RewriteRule ^redirtest.php redirtest.php [L]
  6. rance

    rance aMember Pro Customer

    Joined:
    Dec 1, 2012
    Messages:
    42
    I have edited .htaccess to insert. (see below)

    I still can not access it. I actually tried something simple. I copied the index.php to index2.php just to see if I could hit it, no luck. So I am wondering if I have the right location.
    The redirect file is at:
    http://myurl.com/member/redirect.php. Is this the right place?
    Any assitance would be greatly appriciated.

    Rance


    To answer the why, we are doing a quick integration with another of our systems on PostgreSQL (System B).
    3 steps.
    1. On signup triger event to tell the other system the new user name to create profile (another post)
    2. On login redirect to System B with username (this post)
    3. Validate back with: http://example.com/amember/api/check-access/by-login?_key=APIKEY&login=test
    (working well)



    Code:
    <IfModule mod_rewrite.c>
        RewriteEngine on
    # You may need to uncomment the following line if rewrite fails to work
    # RewriteBase must be setup to base URL of your aMember installation without
    # domain name
        RewriteBase /amember
        RewriteRule ^public public.php [L]
        RewriteRule ^js.php js.php [L]
        RewriteRule ^mysql4.php mysql4.php [L]
        RewriteRule ^index2.php index2.php [L]
        RewriteRule ^redirtest redirtest.php [L]
        RewriteRule !\.(js|ico|gif|jpg|png|css|swf|csv|html)$ index.php
    </IfModule>
  7. rance

    rance aMember Pro Customer

    Joined:
    Dec 1, 2012
    Messages:
    42
    OK, I have redirtest.php access. I can't get the API to work.

    I am getting an error anytime I try to access Lite.php 500 server error
    This is the current code:
    Code:
    <?php
    include "/amember/library/Am/Lite.php";
    $user = Am_Lite::getInstance()->getUser();
    if(!$user)
    header('Location: /amember/login');
    else
      header('Location: http://dev.ivestplus.com/investage/market.form/'.$user['user_id']);
    ?>
    
    One question is about location. The docs say from outside aMember to use "include"
    This is in the aMember root dir. Is this ok?
    Any idea?
  8. rance

    rance aMember Pro Customer

    Joined:
    Dec 1, 2012
    Messages:
    42
    One note on this. I do have the main API plugin active
  9. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Please check your server's error log, if there was an error, it should be logged, and there should be additional info why it was generated.
  10. rance

    rance aMember Pro Customer

    Joined:
    Dec 1, 2012
    Messages:
    42
    SOLVED> posting for others it may help. So I looked at the server logs. Error was a path issue.

    I added /var/www in front of the /amember sub dir and it worked perfect. One other point I use ['login'] for the user name vs ['user_id'] which is the number.

Share This Page