redirect to home page after login, rather than to member.php

Discussion in 'Customization & add-ons' started by david05, Sep 5, 2005.

  1. david05

    david05 New Member

    Joined:
    Jul 4, 2005
    Messages:
    40
    Hi,

    Can anyone tell me how to redirect the user automatically back to the home page rather than the default member.php page. Thanks.

    David
  2. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    If you are using login.php, you should set Product URL to "/"
    In this case, user will be redirected to homepage after login (if he has active subscription).
  3. wgrismore

    wgrismore aMember Pro Customer

    Joined:
    Oct 16, 2009
    Messages:
    3
    Exactly how do you do this?

    Is this done in the login.php file or in site config. And if it is done in the login.php file exactly here would you enter this?
  4. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,435
    If logging in via login.php, the member is redirected to the product URL set in the product. If using multiple products, they may be sent to the members page.
    You can hardcode the login.html to force it to go to a specified page.

    Add this:

    <input type="hidden" name="amember_redirect_url" value="/yournewurl" />


    David
  5. rodrico101

    rodrico101 New Member

    Joined:
    Nov 17, 2009
    Messages:
    11
    Along the same lines.....

    How can you redirect it to the page they logged in from? I have a log in box on each of several pages.

    Thanks,
    Rod
  6. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,435
    <input type="hidden" name="amember_redirect_url" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/>

    David
  7. rodrico101

    rodrico101 New Member

    Joined:
    Nov 17, 2009
    Messages:
    11
    Where exactly should I place that code and does it replace another line of code. I tried a few different things and it always takes me to member.php after logging in on the redirect.

    Thanks,
    Rod
  8. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    You should place that code in your login form. But this code will work only if you have login form in php pages.
  9. rodrico101

    rodrico101 New Member

    Joined:
    Nov 17, 2009
    Messages:
    11
    Do you mean edit the login.html page or edit the login script on my php pages?
    All my pages are in php. Exactly where would it go in the code?
  10. rodrico101

    rodrico101 New Member

    Joined:
    Nov 17, 2009
    Messages:
    11
    I am using this line of code on my php pages:

    Code:
    <?php
    if ($au=$_SESSION['_amember_user']){ // user is logged-in
    print "Hello $au[name_f] $au[name_l]!<br /><br />";
    print "<a href='/amember/logout.php'>Logout</a>";
    } else { // user is not logged-in
    print "<form method=post action='/amember/login.php'>
    Username: <input style='border: 1px solid #006;' type=text name=amember_login size=10><br>
    Password: <input style='border: 1px solid #006;' type=password name=amember_pass size=10><br>
    <input style='background-color: #d44c07; font-weight: bold; font-size: 12px; color: white;' type=submit value='Login'>
    </form>";
    }
    ?>
    Where do I place the above line to redirect it to the page it was logged in from?

    Rod
  11. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,435
    Place it after the password box:

    Password: <input style='border: 1px solid #006;' type=password name=amember_pass size=10><br>
    <input type="hidden" name="amember_redirect_url" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/>

    David
  12. rodrico101

    rodrico101 New Member

    Joined:
    Nov 17, 2009
    Messages:
    11
    OK....I must be a complete idiot. I placed the line of code where you stated and I get this error:
    Is it because I am trying to add a php command ie the echo$_Server part while it is already in a php code statement (the else part) I am fairly new to php programming. Sorry for the repeated questions.

    Rod
  13. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Here is correct code:
    Code:
    <?php
    if ($au=$_SESSION['_amember_user']){ // user is logged-in
    print "Hello $au[name_f] $au[name_l]!<br /><br />";
    print "<a href='/amember/logout.php'>Logout</a>";
    } else { // user is not logged-in
    print "<form method=post action='/amember/login.php'>
    <input type='hidden' name='amember_redirect_url' value='".$_SERVER['REQUEST_URI']."'/>
    Username: <input style='border: 1px solid #006;' type=text name=amember_login size=10><br>
    Password: <input style='border: 1px solid #006;' type=password name=amember_pass size=10><br>
    <input style='background-color: #d44c07; font-weight: bold; font-size: 12px; color: white;' type=submit value='Login'>
    </form>";
    }
    ?>
    
  14. rodrico101

    rodrico101 New Member

    Joined:
    Nov 17, 2009
    Messages:
    11
    THANKS......works like a charm!!
  15. robertbruce

    robertbruce New Member

    Joined:
    Apr 4, 2008
    Messages:
    15
    I also would like to have members redirected to the home page but this thread has left me confused about which file is being edited to do the redirect.

    Can you direct me to the correct file and directory please. My login.php file looks like this:

    <?php
    /*
    * Members page, used to login. If user have only
    * one active subscription, redirect them to url
    * elsewhere, redirect to member.php page
    *
    *
    * Author: Alex Scott
    * Email: alex@cgi-central.net
    * Web: http://www.cgi-central.net
    * Details: Member display page
    * FileName $RCSfile$
    * Release: 3.1.8PRO ($Revision: 3266 $)
    *
    * Please direct bug reports,suggestions or feedback to the cgi-central forums.
    * http://www.cgi-central.net/forum/
    *
    * aMember PRO is a commercial software. Any distribution is strictly prohibited.
    *
    */

    if (@$_GET['_test_'] != '' ||
    in_array(@$_GET['_test_'], array('file', 'root_url', 'root_surl'))){
    header("Content-type: text/javascript; charset=UTF-8");
    echo $_GET['_test_'];
    exit();
    }

    include('./config.inc.php');
    $t = & new_smarty();
    $_product_id = array('ONLY_LOGIN');

    if (isset($_REQUEST['amember_redirect_url']))
    $_SESSION['amember_redirect_url'] = $_REQUEST['amember_redirect_url'];

    function rcmp_begin_date($a, $b){
    return strcmp($b['begin_date'], $a['begin_date']);
    }

    include($config['plugins_dir']['protect'] . '/php_include/check.inc.php');
    $payments = & $db->get_user_payments(intval($_SESSION['_amember_id']), 1);
    usort($payments, 'rcmp_begin_date');

    $now = date('Y-m-d');
    $urls = array();
    foreach ($payments as $k=>$v){
    if (($v['expire_date'] >= $now) && ($v['begin_date'] <= $now)) {
    $p = get_product($v['product_id']);
    $url = $p->config['url'];
    if (strlen($url)){
    $urls[] = $url;
    }
    }
    }

    if ($_SESSION['amember_redirect_url']) {
    $redirect = $_SESSION['amember_redirect_url'];
    unset($_SESSION['amember_redirect_url']);
    } elseif (count(array_unique($urls)) == 1){
    $redirect = add_password_to_url($urls[0]);
    } else {
    $redirect = $config['root_url'] . "/member.php";
    }
    #print_r($urls);
    html_redirect("$redirect", 0, 'Redirect', _LOGIN_REDIRECT);
    ?>
  16. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    If you have only one product set aMember CP -> manage products -> Edit Product -> product URL
    This url will be used by amember to redirect users after login.
  17. quirk

    quirk Member

    Joined:
    Apr 1, 2011
    Messages:
    76
    I have tried to use these solutions on my own site but keep getting error messages.

    Tried to put quick log in form in www/index.php (and no other code at all) & either get
    Parse error: syntax error, unexpected $end in /home/website/public_html/index.php on line 1
    or
    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/website/public_html/index.php on line 1

    amember is in www/amember
    and the product is in www/anotherdirectory

    Help please, thanks!
  18. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,435
  19. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Also, if possible, please attach code that you have in index.php I will help on exact example.
  20. quirk

    quirk Member

    Joined:
    Apr 1, 2011
    Messages:
    76
    I copied this directly from earlier posts: In www.index.php I have

    PHP:
    if ($au=$_SESSION['_amember_user']){ // user is logged-in
    print "Hello $au[name_f] $au[name_l]!<br /><br />";
    print 
    "<a href='/amember/logout.php'>Logout</a>";
    } else { 
    // user is not logged-in
    print "<form method=post action='/amember/login.php'>";
    print 
    "<input type='hidden' name='amember_redirect_url' value='".$_SERVER['REQUEST_URI']."'/>";
    print 
    "Username: <input style='border: 1px solid #006;' type=text name=amember_login size=10><br>";
    print 
    "Password: <input style='border: 1px solid #006;' type=password name=amember_pass size=10><br>";
    print 
    "<input style='background-color: #d44c07; font-weight: bold; font-size: 12px; color: white;' type=submit value='Login'>";
    print 
    "</form>";
    }
    I did wonder if
    PHP:
    if ($au=$_SESSION['_amember_user'])
    should be
    PHP:
    if ($au==$_SESSION['_amember_user'])
    but that didn't help.

Share This Page