K
K
Konstantin Lavrovsky2020-04-28 11:50:55
WordPress
Konstantin Lavrovsky, 2020-04-28 11:50:55

Why is there a cookie error on wordpres?

Good afternoon, the site has implemented authorization through this form

<form method="POST" class="callback" name="loginform" id="loginform"  action="<?php bloginfo('url') ?>/wp-login.php">
  <label for="user_login">
    <span class="placeholder">Логин</span>
    <input type="text" name="log" id="user_login" autocomplete="off">
  </label>
  <label for="user_pass">
    <span class="placeholder">Пароль</span>
    <input type="password" name="pwd" id="user_pass" autocomplete="off">
  </label>
  <div class="button_wrapper">
    <button name="wp-submit">Отправить</button>
  </div>
  <input type="hidden" name="redirect_to" value="https://site.ru">
  <input type="hidden" name="testcookie" value="1">
</form>

The problem is that the form, if you have never logged in from this browser before, or go in incognito, does not work right away, although the login and password are suitable and log in after several attempts ...
If you try several times, the moment will come when we will be thrown in wp-login where it will give us an error 5ea7ed2445847732752087.png
. And after updating this page, an alert pops up confirming the resubmission of the form, click continue and we are calmly logged in and thrown to the main page.
In function.php I have a couple of redirects to prevent users from logging into wp-admin or wp-login
function custom_login_page() {
  $new_login_page_url = home_url( '/enter/' ); // new login page
  global $pagenow;
  if( $pagenow == 'wp-login.php' && $_SERVER['REQUEST_METHOD'] == 'GET' OR $pagenow == '/wp-admin/' ) {
    wp_redirect($new_login_page_url);
  exit;
  }
}
if( !is_user_logged_in() OR !current_user_can('administrator') ){
  add_action('init','custom_login_page');
}
add_action( 'init', 'blockusers_init' );
function blockusers_init() {
  if ( is_admin() && ! current_user_can( 'administrator' ) &&
  ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
  wp_redirect( home_url( '/enter/' ) );
  exit;
  }
}

But when we get to the wp-login page and this error (screenshot) is given, we are left on the wp-login page, which is strange for me personally.
There are a couple of options, try ajax`om to send the registration form to the same wp-login.php, will it help?
Or is it affected by the redirect from wp-login to site.ru/enter
What should I do and what could affect this?
I sinned on the http link before, that is, the site was without a certificate, changed to https - installed the certificate. but the error didn't go away...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Lavrovsky, 2020-04-28
@s1mypj

Fixed by submitting the form via ajax, but such a crutch, just awful...
Still waiting for advice on solving this problem.
My crutch

$('#loginform').submit(function(event) {
  event.preventDefault();
  var url = $(this).attr('action');
  var logindata = $(this).serialize();
  $.ajax({
    url: url,
    type: 'POST',
    data: logindata,
  })
  .done(function() {
    var url = $('#loginform').attr('action');
    var logindata = $('#loginform').serialize();
    $.ajax({
      url: url,
      type: 'POST',
      data: logindata,
    })
    .done(function() {
      window.location.href = 'https://site.ru/enter';
    })
    .fail(function() {
      console.log("error");
    })
    .always(function() {
      console.log("complete");
    });
  })
  .fail(function() {
    console.log("error");
  })
  .always(function() {
    console.log("complete");
  });
});

Double sending information, because the first time for some reason he does not want to connect.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question