User has to refesh page after logging in with custom login

Discussion in 'Customization & add-ons' started by alexblyz91, Jan 8, 2020.

Thread Status:
Not open for further replies.
  1. alexblyz91

    alexblyz91 New Member

    Joined:
    Aug 9, 2019
    Messages:
    24
    I have set up a custom login form that posts to /amember/login
    The form works and allows me to login, however when the user is directed back to the page after login, i have to refresh to see the membership only content.
    So, when i login, it directs me back to the page, but still shows the login form, then when i refesh the login form dissapears and i see the members content.
    Code below:

    Code:
    <?php
    include("../amember/library/Am/Lite.php");
    $membership=Am_Lite::getInstance()->haveSubscriptions(2);
    $isloggedin=Am_Lite::getInstance()->isLoggedIn();
    $username=Am_Lite::getInstance()->getUsername();
    $silver=Am_Lite::getInstance()->haveSubscriptions(2);
    $gold=Am_Lite::getInstance()->haveSubscriptions(4);
    $email=Am_Lite::getInstance()->getEmail();
    ?>
    
    <?php if($isloggedin >=1):?>
    
    Members only content
    
    <?php else:?>
    
    
    
                      <form action="site.com/amember/login" method="post" class="rd-form rd-mailform">
                        <div class="form-wrap">
                          <label class="form-label" for="form-login-name-1">Login</label>
                          <input class="form-input" id="form-login-name-1" type="text"  name="amember_login" data-constraints="@Required">
                        </div>
                        <div class="form-wrap">
                          <label class="form-label" for="form-login-password-1">Password</label>
                          <input class="form-input" id="form-login-password-1" type="password" name="amember_pass" data-constraints="@Required">
                        </div>
                        <label class="checkbox-inline checkbox-inline-lg checkbox-light">
                          <input name="input-checkbox-1" value="checkbox-1" type="checkbox">Remember Me
                        </label>
                        <button class="button button-lg button-primary button-block" type="submit">Sign in</button>
                      </form>
                     
                    </div>
                    <div class="card-form card-form-register">
                      <form class="rd-form rd-mailform" data-form-output="form-output-global" data-form-type="contact" method="post" action="bat/rd-mailform.php">
                        <div class="form-wrap">
                          <label class="form-label" for="form-register-email">E-mail</label>
                          <input class="form-input" id="form-register-email" type="email" name="email" data-constraints="@Email @Required">
                        </div>
                        <div class="form-wrap">
                          <label class="form-label" for="form-login-name-2">Login</label>
                          <input class="form-input" id="form-login-name-2" type="text" name="form-input" data-constraints="@Required">
                        </div>
                        <div class="form-wrap">
                          <label class="form-label" for="form-login-password-2">Password</label>
                          <input class="form-input" id="form-login-password-2" type="password" name="password" data-constraints="@Required">
                        </div>
                        <div class="form-wrap">
                          <label class="form-label" for="form-login-password-3">Repeat Password</label>
                          <input class="form-input" id="form-login-password-3" type="password" name="password" data-constraints="@Required">
                        </div>
                        <button class="button button-lg button-primary button-block" type="submit">Create new account</button>
                      </form>
    
    <?php endif; ?>
    
    how do i fix this?
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hello,

    I can not be sure but it looks like browser cache.

    What is Expires http header your page with login form sent?

    Thanks.
  3. alexblyz91

    alexblyz91 New Member

    Joined:
    Aug 9, 2019
    Messages:
    24
    Hi Caesar,
    I think you are right and the response headers are causing the issues.
    After the login request the server responds with:
    Code:
    HTTP/1.1 200 OK
    Date: Thu, 09 Jan 2020 11:19:56 GMT
    Server: Apache
    Set-Cookie: PHPSESSID=ilg9qlncrb36h86n7hu8j0uab4; path=/; domain=.domain.com; HttpOnly
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate
    Pragma: no-cache
    Set-Cookie: amember_nr=776e47c30cdfc8493510074ed040911b; path=/; domain=.domain.com; HttpOnly
    Set-Cookie: phpbb3_tfbuh_sid=8dee42d448f03beaefc986f01bef1191; path=/; domain=.domain.com
    Set-Cookie: phpbb3_tfbuh_u=50; path=/; domain=.domain.com
    Content-Length: 59
    Connection: close
    Content-Type: application/json; charset=UTF-8
    
    It looks like
    The cookie expired over 30 years ago

    I've removed all custom headers from my apache config and its still doing this so not sure what could be causing it.
    Any ideas?

    Thanks
    Last edited: Jan 9, 2020
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    These headers is correct actually. Expires in past means cache by browser is disabled (it is not related to cookie, it is related to full document).

    Can you give me url of page with your custom login form (or headers from this page with your login form)?
  5. alexblyz91

    alexblyz91 New Member

    Joined:
    Aug 9, 2019
    Messages:
    24
    I managed to get it working by using the following code i found on another post:


    Code:
                    <form name="login" method="post" action='../members/login'>
                        <fieldset>
                            <legend>&nbsp;&nbsp;Member Login</legend>
                            <div class="row">
                                <div class="element-title">
                                    <label class="element-title" for="login">E-Mail Address or Username</label>
                                </div>
                                <div class="element">
                                    <input type="text" id="login" name="amember_login" size="15" value="" />
                                </div>
                            </div>
                            <div class="row">
                                <div class="element-title">
                                    <label class="element-title" for="pass">Password</label>
                                </div>
                                <div class="element">
                                    <input type="password" id="pass" name="amember_pass" size="15" />
                                </div>
                            </div>
                            <div class="row">
                                <div class="element" style="vertical-align: baseline">
                                    <input type="submit" value="Login" />
                                    <span style="font-size: large"> or
                                        <a href="javascript: history.back(-1)">Back</a>
                                    </span>
                                </div>
                            </div
                        </fieldset>
                    </form>
    
    Only difference i can see is this one has id's and a form name.
    Thanks for the help.
    i didn't think that ids were needed to post the data? so not sure why it works but im not complaining!
  6. alexblyz91

    alexblyz91 New Member

    Joined:
    Aug 9, 2019
    Messages:
    24
    Update
    The above example works in Chrome and on iOS and Android phones, but not mozilla firefox.
    I've tested in firefox on 2 different devices and it doesn't work, not sure why
  7. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    In event of you do not want to show URL of your page in public here then you can submit ticket on helpdesk:
    https://www.amember.com/support
    and we will check it.

    I am afraid I can not help without this url and example of user login/password.

    Thanks.
  8. alexblyz91

    alexblyz91 New Member

    Joined:
    Aug 9, 2019
    Messages:
    24
    I have submitted a ticket.

    Thanks
  9. alexblyz91

    alexblyz91 New Member

    Joined:
    Aug 9, 2019
    Messages:
    24
    Update:
    My issue has been resolved by the great support team, it was a problem with a javascript file that i was using in my template that was interfering with the login process.

    Thanks!
Thread Status:
Not open for further replies.

Share This Page