The solution to the cookie error in the login management background when the WordPress multi-site network is distributed in different primary domain names

The title is very long…but I still feel that it is necessary to describe the background of the error at the beginning of the article. If you read the title and know what I’m talking about, you can jump directly to the ” Solutions ” section.

background knowledge

Multisite network is a feature of WordPress that allows users to create and run multiple WordPress websites on a single WordPress dashboard, and these websites can be assigned different primary domains .

Having said that, as the saying goes “there are no two days, (…) 1 “, in a multisite network, only one site can be designated as the primary site (usually the one that exists first).

After creating a sub-site whose main domain name is different from the main site, once you want to access the management background and enter your account and password, you will be notified:

Error: Your browser blocks or does not support cookies. You must enable cookies to use WordPress.

If your site language is English, this error will appear as:

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

For example, if your main site is sanguok.com , and another sub-site in the same network is example.com 2 , you may encounter this problem when trying to log in to example.com ‘s management background.

solution

If you use the panel software to manage the server, you can directly access the panel’s file manager and complete the following operations

First, clear the browser cache (including cookies) and the server cache for cache plugins, etc.

Then access the root directory of the WordPress site through FTP, etc. (that is, where there are subdirectories such as wp-admin , wp-content , etc.);

In the wp-config.php file, add (or set) the following:

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

Congratulations, the site is now up and running.

Correction of another scheme circulating on the Internet

When I tried to find a solution through a search engine, I found that there was another solution circulating on the Internet.

As pointed out by netizen bulgaru , in the wp-config.php file, add (or set) the following:

 define('WP_ALLOW_MULTISITE', true); define('MULTISITE', true); define('SUBDOMAIN_INSTALL', false); define('DOMAIN_CURRENT_SITE', 'your-domain.com'); // 山月按:将your-domain.com改为您实际的主域名,例如sanguok.com define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1); define('SUNRISE', 'on');

Another option states to add (or set) the following to the wp-config.php file:

 // Set cookie domain for login cookies define( 'COOKIE_DOMAIN', '.your-domain.com' ); // 山月按:将your-domain.com改为您实际的主域名,例如sanguok.com

This modification might usually work, but it didn’t work in the case presented here. This is because the case in this article has the peculiarity of “different primary domain names”. Whether it’s DOMAIN_CURRENT_SITE or COOKIE_DOMAIN , you can only define as one value, not multiple values.

For example, if you have both sanguok.com and example.com , no matter who you assign DOMAIN_CURRENT_SITE or COOKIE_DOMAIN to, it will result in a cookie error for the remaining site. Therefore, the method described in this chapter does not work under the special condition of “different primary domain names”.

Rebuild configuration files: eliminate the problem itself

As the saying goes: “Destroy the problem itself, not solve the problem.” If the aforementioned methods do not work, it may be that there are other errors in wp-config.php , such as coding errors, configuration errors, etc.

As shown in the figure, wp-config.php may have encoding errors

Going through the code line by line using control variables might be a solution.

But if you are impatient, you can simply overthrow it and start over. Rename wp-config-sample.php in the root directory of the website to wp-config.php (if you cannot find it, download the latest WordPress installation package and take out the wp-config-sample.php file), and manually Modify the configuration information inside, upload and replace.

Bypassing cookie requests: killing the person asking the question

If the cookie error always occurs, in order to be able to log in to the management background, you may consider the following solutions-

Add the following code snippet to your theme’s functions.php file:

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

Doing so can ignore requests from websites to check cookies and simply log in.

But preventing errors doesn’t eliminate the problem itself. If the cookie error exists objectively, the function of the corresponding website that depends on the cookie still cannot be realized. For example, you cannot open an encrypted article on a site with a cookie error – every time you enter the correct password, click OK, and after the page is refreshed, you will still stay on the interface of entering the password, repeating infinitely. Because the problem is still there, you just eliminate the “problem”.

some panacea

After struggling with WordPress for so long, the author found some panacea-style troubleshooting ideas. Although it is not for the cases cited in this article, and it may not work in all cases, the rights and resources are referenced and listed below.

.htaccess problem?

As pointed out by netizen Marc, many of the problems with WordPress multisite networks are due to the configuration of .htaccess 3 .

Review and troubleshoot the code if you can.

Otherwise, delete the .htaccess file from the server (it is recommended to make a backup before deleting it).

If the problem resolves naturally, go to the site settings, and save the permalink settings, a new .htaccess file will be created automatically.

Plugin problem?

Disable all plugins via FTP etc.

Rename the plugins folder under the website directory to any character. For example, please bring out your catboy (if you have one) and rename it to njfgtews 4 , make sure that this string is different from other folders in the same directory 5 . As a result, all plugins will be disabled.

If the problem is solved naturally, please leave the catboy (if any), change the folder name back to plugins , and enable the plugins one by one to ensure that the problem does not recur. If the problem recurs, congratulations on finding the source.

Typically, caching or security plugins cause such problems.

HTTPS problem?

If you have the SSL plugin installed, check that it redirects to HTTPS correctly.

topic question?

WordPress themes are also an unexpected source of problems.

You can rename the folder where the theme is stored to any character, just as I did for the catboy (if any) mentioned earlier. After that, the site will revert to the default WordPress theme, such as “2022”, and the theme-related issues will disappear.

If so, delete the theme that was used when the site was in trouble.

Epilogue

Through the above introduction, you should know the solution to the cookie error in the login management background when the WordPress multi-site network is distributed in different primary domain names. If you still have questions, or have comments to guide, please leave a message in the comment area. You can also browse more WordPress tips summarized by the author , and subscribe to RSS of WordPress related articles .

1 From “Book of Rites, Zeng Ziwen” – or whatever you think it is, meaning there are no two suns in the sky. The following is omitted.
2 This domain name is actually a sample site held by IANA.
3 In simple terms, .htaccess files manage user access to website directories. Read Wiliz’s ” .htaccess in depth” to learn more.
4 A string of characters meaningless to human beings only exists in the library of Babel written by Borges.
5 is to make sure that the string of characters doesn’t make sense to the machine either.

This article is reprinted from: https://sanguok.com/blog/solution-for-cookie-error-when-logging-into-admin-backend-when-network-sites-have-their-own-main-domain-name/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment