Insert Login/Logout to any page

Discussion in 'Customization & add-ons' started by dudaah, Jun 9, 2004.

  1. davidm1 aMember User & Partner

    Member Since:
    May 16, 2006
    Message Count:
    4,404
    Where are they loggin in from?

    You can hardcode it in the login.html file:
    <input type="hidden" name="amember_redirect_url" value="/new-url/" />

    David
  2. jdaspects New Member

    Member Since:
    Dec 11, 2007
    Message Count:
    3
    Login Logout in wordpress footer.php

    Hi Alex and David M.,

    I have an issue with amember not passing over values on the login link

    Using revolution theme revolution city you can look at the www.revolutiontwo.com/demo/church.html theme to see the Login link on the black footer bar.

    I would like to use this Link for logging members in and out as well as the amember sidebar widget if I decide to.

    Right now the footer.php file shows this

    <!-- begin footer -->

    <div style="clear:both;"></div>

    <div id="footer">

    <p>Copyright &copy; 2009 .... &middot; All Rights Reserved &middot; <?php wp_loginout(); ?> </p>

    </div>

    <?php do_action('wp_footer'); ?>

    </div>

    </body>
    </html>

    How can I get this link to redirect to the amember login page?

    Thanks,

    Jonathan
  3. nashkj aMember Pro Customer

    Member Since:
    Feb 11, 2009
    Message Count:
    10
    Hi sorry to drag everybody back through this thread but I am new to amember and have read through this post quite a few times and cannot come up to a firm conclusion about what it is that needs to be done here.

    In short I want to add login username and password detail to my pages and have them change to show the loggin in username when the user is logged in.

    Can we have a step by step summary on the outcome of this thread.

    eg look at my questions below and consider the steps from someone who knows only basic html and has never made a php page in his life

    1. Is it that you can only get this to work if all pages are in the amember directory or will it work on the pages outside of it?

    2. Assuming that you can use it on pages outside of this directory is the next thing then that you have to create a php page for every html page that I have.

    3. If this is correct is it a simple operation to rename the existing page to .php instead of .html

    4. If this is correct and I then copy and past the code from draj post #30 will this work? or is there more to show the username once logged in.

    5. Once I know how to get this far and get the code on the page at what point can I break it up to move the login box/password box and to display the username when logged in? It seems the Php code has to go to the top?

    really would appreciate help on this it is one of those little things that is starting to niggle
  4. cmaclean aMember Pro Customer

    Member Since:
    Feb 10, 2009
    Message Count:
    2
    Incorrect Login

    Hi Everyone,

    I have inserted a login form on one of my custom pages (mysite.com/login.html) which works perfectly. One little quirk - if someone enters an incorrect username or password and hits login, instead of the same page reloading with the error message, it loads mysite.com/amember/login.php (which isn't customized) with the error message.

    Has anyone been able to get around this?

    Thanks!
  5. bjarkemt New Member

    Member Since:
    Oct 1, 2009
    Message Count:
    4
    I have just used it with success on my site http://www.ThatLovelyRomance.com... And I have a question..

    Say that you have two different kinds of membership... a free and a paid.. Now if I only want some information to be show, e.g. "a upgrade button" (from free to paid), for the user who is logged on and only has a free membership but not a paid?


    a side note:
    To get the function to work on all my pages, I had to add
    <?php session_start(); ?>
    to the top of every page on my site... workes like a charm :)
  6. alexander Administrator

    Member Since:
    Jan 8, 2003
    Message Count:
    5,909
    You can use this code:
    Code:
    if(!$_SESSION[_amember_user][data][status][1]){
    print "Code for upgrade button"; 
    }
    
    Where 1 is your paid product id
  7. bjarkemt New Member

    Member Since:
    Oct 1, 2009
    Message Count:
    4
    I hope that you mean like this :)

    if($_SESSION[_amember_user][data][status][1]){
    print "Code for upgrade button";
    }

    anyway, this works, and thank you yet again :D
  8. alexander Administrator

    Member Since:
    Jan 8, 2003
    Message Count:
    5,909
    Yes sorry for the typo )
  9. rodrico101 New Member

    Member Since:
    Nov 17, 2009
    Message Count:
    11
    I am using this login/out code for each of 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'>
    <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'><br />
    <a href='http://www.jeffinsandiego09.com/amember/login.php'>I forgot my password</a><br />
    </form>";
    }
    ?>
    (It's been modified for my site) When a person is logged in their name appears above the logout link -EXCEPT for on my amember subscription pages. It just says "Hello" and does not pull the user names. I am using the php session start line at the top of the page. Is there some modification I need to use to display the names on my subscription pages? Technically I do not need a login box on the page because they will already be logged in to access it.

    Any help would be appreciated.

    Rod
  10. nkowalk New Member

    Member Since:
    Mar 21, 2010
    Message Count:
    3
    Thanks for all the help with this topic - it's been invaluable to me!

    On this same subject, I'd like to have a link to the aMember admin CP for administrator users only on my website pages after logging in. What session variable would I use to determine whether a user is an admin?

    Thanks!
  11. alexander Administrator

    Member Since:
    Jan 8, 2003
    Message Count:
    5,909
    you can test $_SESSION['amember_admin'] variable.
  12. demyurg New Member

    Member Since:
    May 16, 2010
    Message Count:
    7
    Hi,

    I'm trying to add a logout button into the navigation of a static html page. I've tried the codes from the previous pages but I believe that they are for something else.

    My members login at site.com/amemeber/member.php. From here they can go to the membership folder which has an index.html file. And I would like to add a log out to this navigation so that they do not need to go back to member.php to log out.

    Any ideas?
  13. alexander Administrator

    Member Since:
    Jan 8, 2003
    Message Count:
    5,909
    Use this code:
    Code:
    <a href='/amember/logout.php'>Logout</a>
    
  14. demyurg New Member

    Member Since:
    May 16, 2010
    Message Count:
    7
    thanks a lot alexander..I'm amazed at how simple it was
  15. mumser101 New Member

    Member Since:
    Oct 1, 2009
    Message Count:
    26
    I am using the above code and it works fine whenever a user logs in. However, when a new user signs up and clicks on the confirmation email message link they get: "Your username and password have been emailed. To access your account now please click here to Login ". After clicking on Login, they are automatically redirected to the protected area, but the phrase that says "Hello [first name] is missing, and the login fields are showing as if they are not logged in. I suspect that the session variable is not set when logging in in this manner. So, how can I set this variable so that the above code will see the user as if they actually manually logged in and present the page the way it should be?

    Thanks for your assistance.
  16. alexander Administrator

    Member Since:
    Jan 8, 2003
    Message Count:
    5,909
    Variables should be set in this situation. When you open /amember/member.php after click on the link is user really logged in?
  17. slinky aMember Pro Customer

    Member Since:
    Jul 15, 2010
    Message Count:
    200
    I have the exact same problem using vBulletin and I just sent in a ticket to support.

    If I print out the session information using:

    print_r($_SESSION);

    It properly prints out all the variables. But what happens is that I cannot access each variable in the manner that you described above. Those calls are lost and there is a blank space for:

    print_r($_SESSION['_amember_user']);

    This is why when you go further down the page where the login/logout for amember is, it doesn't work. The if statement evaluating login does not seem to work and be able to pull the user number so that it knows it's above 0 on vbulletin pages for me. Also with another script same thing. Works great though in wordpress.
  18. slinky aMember Pro Customer

    Member Since:
    Jul 15, 2010
    Message Count:
    200
    OK - another interesting development. On your Joomla page, use this:


    if ($_SESSION['user_id'] > 0){

    Instead of

    if ($user['member_id'] > 0){

    and that WILL work for one of my scripts. There is a conflict of some sort here.

    -----------

    FOLLOW UP: Using this did the trick for the other script:


    if ( ($user['member_id'] > 0) || ($_SESSION['user_id'] > 0) ){
  19. microvb aMember Pro Customer

    Member Since:
    Nov 23, 2007
    Message Count:
    43
    Joomla is a terrible choice, but there is a fix outside of switching CMS's

    The conflict I found with members who choose to integrate this program with Joomla, is that Joomla is not a third-party script friendly application.

    1. Joomla uses common names for variables such as "$user". This typically makes integration using includes pretty much impossible (or at least the trouble involved vs the development cost is rarely worth the effort).

    2. Joomla wants to take complete control over users and sessions. This causes a problem where calling "session_start()" fails and if success causes Joomla to fail (in a lot of cases).

    But do not fret you Joomla lovers out there (personally, it leaves a very sour taste in my mouth which is why I am giving this free tip).

    The most solid method for working around these problems without creating too much of a nightmare, is as follows:

    Inside aMember's root folder, create a simple script. There are two ways to write this script -- hard code a database query, or insert your "session_start()" code there. Make this script simple enough that all it does is respond with a 1 or a 0. You will be using this flag in Joomla later.
    PHP:

    <?php
    session_start
    ();
    $loggedin 0;
    if(!empty(
    $_SESSION['_amember_user'])) {
       
    // User is logged in to aMember
       
    $loggedin 1;
    } else {
       
    // User is not logged in to aMember
    }
    echo 
    $loggedin;
    ?>

    Inside of Joomla, add some nice jQuery code which will grab the data from the script you just made in aMemeber.
    PHP:

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
    <script>
    $(document).ready(function() {
      $.get('/amember/checksession.php', function(data) {
             // Do whatever you want with the variable "data" here
      });
    });
    </script>

    This integration is clean, and leaves both installations near virgin state requiring only minimal change to Joomla's template, and a small file inside /amember/ folder. This will also work for anything outside of Joomla -- however if you wish to keep your sanity during a Joomla integration, heed the following warnings:

    1. Let aMember handle ALL user management, and page protection. Yes Joomla tries with it's own login system, but if you are reading this, it is most likely that you wish to integrate aMember for whatever reason.

    2. Do not play with altering Joomla's sessions, or session control. The effort here would result in many hours (days, months, years, forever ?) of wasted time, and would break the ability to simply update Joomla when the need arises. Their code is all over the place!

    Thats pretty much it for all you Joomla-ites out there!
  20. avortelinc aMember Pro Customer

    Member Since:
    Jan 5, 2007
    Message Count:
    12
    Can anyone tell the code to using an image instead of printing text. Currently I am using this code:

    <?php
    if ($au=$_SESSION['_amember_user']){ // user is logged-in
    print "<a href='/logout.php'>Logout</a>";

    } else { // user is not logged-in
    print "<a href='https://sitename.com/login.php'>Login</a>";
    }
    ?>

    Instead of Login /Logout text, I like to use a Login Image / Logout Image

Share This Page