Wordpress admin login cookies blocked error after

2019-03-11 01:18发布

Background: had a working Wordpress 3.7 site at olddomain.com.

I moved it to newdomain.com successfully, and in the process added this to wp-config:

define('WP_HOME','http://newdomain.com');
define('WP_SITEURL','http://newdomain.com');

Now when I attempt to login from newdomain.com/wp-admin I'm getting the cross-browser error (despite having cookies enabled and clearing existing cookies):

ERROR: Cookies are blocked or not supported by // your browser. 
You must enable cookies to use WordPress.

I tried going into wp-login.php and commenting out the following lines (744-747) to stop the conditional testcookie check

    // If cookies are disabled we can't log in even with a valid user+pass
if ( isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE]) )
    $user = new WP_Error('test_cookie', __("<strong>ERROR</strong>: Cookies are blocked or not supported by // your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to use WordPress."));
else
    $user = wp_signon('', $secure_cookie);

but doing that leaves me stuck in a redirect loop back to the admin page:

http://myapp.com/wp-login.php?redirect_to=http%3A%2F%2Fmyapp.com%2Fwp-admin%2F&reauth=1

Do I need to change (or not set) the site URL? or is there another potential way to troubleshoot this? thanks

13条回答
何必那么认真
2楼-- · 2019-03-11 01:43

I have been googled & tried all ways to get rid of this cookie issue. Finally i found two solutions, which could help you.

Solution 1:

yoursite/wp-login.php

Comment following lines 770-773

Code

if ( isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE]) )
    $user = new WP_Error('test_cookie', __("<strong>ERROR</strong>: Cookies are blocked or not supported by your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to use WordPress."));
else
    $user = wp_signon('', $secure_cookie);

It might work for some websites and some sites may show blank page. Moreover, this is not recommended,as this file may be overridden after wordpress update so try for second solution.

Solution 2:

yoursite/wp-content/themes/yourthemeFolder/functions.php

Place following code.

 setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
if ( SITECOOKIEPATH != COOKIEPATH )
    setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);

Updating of your theme may also loose these changes so please place this code in another functions.php, which is under your child-theme folder in your current active theme. Hope, this will help you.

查看更多
仙女界的扛把子
3楼-- · 2019-03-11 01:45

This worked for me.

  1. Remove //define('COOKIE_DOMAIN', 'www.domain.com');in your wp-config.php
  2. Ensure that all the files have the ANSI format and not utf-8
查看更多
姐就是有狂的资本
4楼-- · 2019-03-11 01:47

Following step solve my issue

on wp-config.php

//define('WP_CACHE', true); // Added by W3 Total Cache Block this line
//define("COOKIE_DOMAIN", "www.domain.com"); Block this line

Delete following files from wp-content

object-cache.php 
advanced-cache.php
db.php
查看更多
Luminary・发光体
5楼-- · 2019-03-11 01:52

This error also occurs when moving a multisite installation to a new domain if you update all options on the database table (usually wp_options), but forget to change the DOMAIN_CURRENT_SITE line on wp-config.php:

define( 'DOMAIN_CURRENT_SITE', 'yourdomain.com' );
查看更多
成全新的幸福
6楼-- · 2019-03-11 01:52

I was getting this same error.

I had hard coded the Home and SiteURL in wp-config.php for a brand new website - no plugins even installed.

The problem: I had a space at the end of the URL.

define('WP_HOME','http://100.000.000.01/~acctname/wp ');
define('WP_SITEURL','http://100.000.000.01/~acctname/wp ');

Removing the space fixed this error.

define('WP_HOME','http://100.000.000.01/~acctname/wp');
define('WP_SITEURL','http://100.000.000.01/~acctname/wp');
查看更多
对你真心纯属浪费
7楼-- · 2019-03-11 01:53

I created my Multisite install long ago when you needed a plugin for domain mapping. So I had the file '/wp-content/sunrise.php' and in the wp-config define( 'SUNRISE', 'on' ); It's been working just fine until a recent update to WordPress.

I viewed these errors in my debug.log:

Undefined index: HTTP_HOST in ../public_html/wp-content/sunrise.php on line 10
Undefined index: HTTP_HOST in ../public_html/wp-includes/ms-settings.php on line 57

So I deleted the sunrise file and wp-config sunrise definition and added @max4ever/@duck_boy's cookie definitions to the wp-config file:

define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');
define('SITECOOKIEPATH', ''); 

That solved the problem. I can now login!! Note: I tried this definition and it worked as well. Taken from Multisite Setup Guide

define( 'COOKIE_DOMAIN', $_SERVER[ 'HTTP_HOST' ] );
查看更多
登录 后发表回答