1

I have a custom log in form for users of my website where they can log in then view some information that related to them.

The problem is sometimes this form will loop. I will get the message "login sucessfull" but rather than redirecting to the page where it should go, it seems to refresh the login form and users have to enter their details again.

If the user attempts to log in a couple of times it will then allow them in. After this point they can log out/in without issue (for a short period).

I have tried clearing cookies and cache after a sucessfull login to replicate or narrow down the issue. But in this case the login is sucessfull again.

Would anyone have some advice how I could troubleshoot this?

<?php
/*
 * Template Name: Login Form
 */
get_header() ?>
<div class="loading">
  <div class="loading-icon">
    <svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
       width="40px" height="40px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">
    <path fill="#002e5b" d="M43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0,14.615,6.543,14.615,14.615H43.935z">
      <animateTransform attributeType="xml"
        attributeName="transform"
        type="rotate"
        from="0 25 25"
        to="360 25 25"
        dur="0.6s"
        repeatCount="indefinite"/>
      </path>
    </svg>
  </div>
</div>
<?php if(!is_user_logged_in()) { ?>
  <div class="login_form container">
    <div class="row">
      <div class="col-12">
        <form action="login_form">
          <ul class="row login">
            <li class="col-lg-4 offset-lg-4">
              <h2><?php _e('Sign In') ?></h2>
            </li>
            <li class="col-lg-4 offset-lg-4">
              <input placeholder="Enter your email address" type="email" name="email_address">
            </li>
           <li class="col-lg-4 offset-lg-4">
              <input placeholder="Enter your password" type="password" name="password">
            </li>
            <li class="col-lg-4 offset-lg-4">
              <p class="status"> </p>
            </li>
            <li class="col-lg-4 offset-lg-4">
              <?php wp_nonce_field('ajax-login-nonce', 'security') ?>
              <a class="button secondary thick submit" href="#" id="login-button"><?php _e('Sign in >') ?></a>
            </li>
          </ul>
        </form>
      </div>
    </div>
  </div>
<script>
jQuery(window).load(function() {
  login();
});
</script>
<?php } else { ?>
  <script>
    $(document).ready(function() {
      var location = "<?php echo home_url() ?>";
     window.location.href = location;
    });
  </script>
<?php } ?>
<?php get_footer() ?>
  • Without seeing your login form we won't be able to help you any further. – leymannx Apr 8 at 12:15
  • @ leymannx I've asked how I would approach this myself to troubleshoot. I havent asked for someone to fix it for me. – Homegrownandy Apr 8 at 12:40
  • 2
    Ah OK. Then get a proper IDE, maybe PHPStorm and install Xdebug, set a breakpoint in your form, test and inspect what exactly is going on. – leymannx Apr 8 at 12:43
  • @leymannx I've somehow managed to post the code with the help of an edit recomendation. Do I have to provide a link tot the website or would this be enough at the moment? – Homegrownandy Apr 8 at 13:10
  • That's fine! Please don't provide links to your live site as they may be considered spam or malicious and have no value as soon as the issue got fixed. – leymannx Apr 8 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.