php 移动服务器后,Wordpress 管理员登录 cookie 阻止错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20941328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:41:37  来源:igfitidea点击:

Wordpress admin login cookies blocked error after moving servers

phpwordpresscookies

提问by Chris B.

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

背景:在 olddomain.com 上有一个可用的 Wordpress 3.7 站点。

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

我成功地将它移动到 newdomain.com,并在此过程中将其添加到 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):

现在,当我尝试从 newdomain.com/wp-admin 登录时,出现跨浏览器错误(尽管启用了 cookie 并清除了现有 cookie):

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

我尝试进入 wp-login.php 并注释掉以下几行 (744-747) 以停止条件 testcookie 检查

    // 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

我是否需要更改(或不设置)站点 URL?或者是否有另一种可能的方法来解决这个问题?谢谢

回答by max4ever

add to wp-config.php

添加到 wp-config.php

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

original source http://wordpress.org/support/topic/cookie-error-site-not-letting-me-log-in

原始来源http://wordpress.org/support/topic/cookie-error-site-not-letting-me-log-in

回答by Marc

Having migrated hundreds of WP sites, here's a few thoughts :

迁移了数百个 WP 站点后,这里有一些想法:

If migrating the DB : Check the database options table (probably wp_options) column "option_name" that values "siteurl" and "home" have the correct "option_value" for your site. "siteurl" is huge.

如果迁移数据库:检查数据库选项表(可能是 wp_options)列“option_name”,值“siteurl”和“home”对您的站点具有正确的“option_value”。“siteurl”是巨大的。

I can testify that the options table tweak is the bare minimum required to migrate a DB to a new domain in WP. (will not cause redirection, will still have issues)

我可以证明选项表调整是将数据库迁移到 WP 中的新域所需的最低限度。(不会导致重定向,仍然会有问题)

WP looks up these DB options to serialize the site to domain and I am pretty sure the defines are lower in the stack and of no help. Consider the wp-admin activities as loosely coupled to the front. You can break everything (done it) in the front and the admin will still function.

WP 查找这些数据库选项以将站点序列化为域,我很确定定义在堆栈中较低并且没有帮助。将 wp-admin 活动视为与前端松散耦合。您可以在前面破坏所有内容(完成),管理员仍然可以正常工作。

Also - did/does the site work with generic install/no migration or tweaks?

另外 - 该站点是否/是否使用通用安装/无迁移或调整?

As mentioned - .htaccess (missing or misconfigured) will cause your error. Regarding the .htaccess file, if used, this is a dot.file and many operating systems will "ignore" or "make invisible" so a copy/paste or FTP application or similar may not carry the .htaccess

如前所述 - .htaccess(丢失或配置错误)会导致您的错误。关于 .htaccess 文件,如果使用,这是一个 dot.file 并且许多操作系统将“忽略”或“使不可见”,因此复制/粘贴或 FTP 应用程序或类似的可能不会携带 .htaccess

(pretty sure on this) If you moved the DB and used pretty urls, and missed the .htaccess that could be all you need to fix. I just tested locally on a sandbox install and the table wp_option column "option_name" value "permalink_structure" when left blank in column option_value will return to ?p=1 (non-permalink) status and .htaccess will be mostly bypassed.

(对此非常确定)如果您移动了数据库并使用了漂亮的 url,并且错过了 .htaccess,这可能是您需要修复的全部内容。我刚刚在沙盒安装上进行了本地测试,并且表 wp_option 列“option_name”值“permalink_structure”在列 option_value 中留空时将返回到 ?p=1 (非永久链接)状态,并且 .htaccess 将大部分被绕过。

回答by Juan Carlos Conde

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
  1. //define('COOKIE_DOMAIN', 'www.domain.com');在您的 wp-config.php 中删除
  2. 确保所有文件都是 ANSI 格式而不是 utf-8

回答by guico

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_SITEline on wp-config.php:

如果您更新数据库表上的所有选项(通常为wp_options),但忘记更改 上的DOMAIN_CURRENT_SITE行,则在将多站点安装移动到新域时也会发生此错误wp-config.php

define( 'DOMAIN_CURRENT_SITE', 'yourdomain.com' );

回答by Giorgi Khokho

this bug was driving me crazy the last couple of days so i thought after fixing it to share with you guys! the problem was when i was trying to login into my wordpress backend i got this annoying cookies error so this is how i fixed it!

这个错误在过去几天让我发疯,所以我想在修复它之后与你们分享!问题是当我试图登录我的 wordpress 后端时,我遇到了这个烦人的 cookie 错误,所以我就是这样修复它的!

  1. Go to your ftp and your domain.
  2. Afterwards go to your wp-contents
  3. Go to your themes folder
  4. Chose the theme that is active
  5. Look for functions.php of your teem and open it
  6. At the ende of the code you should see closing tag p> just remove it clear the spaces also and save it!
  7. Go to your domain.com/wp-login.php
  8. and try to login it should be fixed afterwards you can put the tag back where it was and save it again that was the solution for me this trick also fixes the white page problem in wordpress
  1. 转到您的 ftp 和您的域。
  2. 然后去你的wp-contents
  3. 转到您的主题文件夹
  4. 选择活跃的主题
  5. 查找您的teem的functions.php并打开它
  6. 在代码的末尾,您应该看到结束标记 p> 只需将其删除并清除空格并保存即可!
  7. 转到您的 domain.com/wp-login.php
  8. 并尝试登录它应该在之后修复您可以将标签放回原处并再次保存它对我来说是解决方案这个技巧还修复了wordpress中的白页问题

Cheers!

干杯!

回答by Ricky A.

I experienced this due to my caching plugin.

由于我的缓存插件,我遇到了这种情况。

W3 Total Cache had added the following to my wp-config.php file:

W3 Total Cache 已将以下内容添加到我的 wp-config.php 文件中:

define('COOKIE_DOMAIN', 'www.olddomain.com'); // Added by W3 Total Cache

Since it was hard coded, it didn't update to the new site domain. After deleting the added code (because I don't currently use the plugin), I was able to log in again.

由于它是硬编码的,它没有更新到新的站点域。删除添加的代码后(因为我目前没有使用该插件),我能够再次登录。

I'd check wp-config.php for the word "cookie" to see if a plugin might have added something like this.

我会检查 wp-config.php 中的“cookie”这个词,看看插件是否添加了这样的东西。

回答by user3186106

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.

我在 wp-config.php 中为一个全新的网站硬编码了 Home 和 SiteURL - 甚至没有安装插件。

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

问题:我在 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');

回答by Raj Ravuri

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

我已经用谷歌搜索并尝试了所有方法来摆脱这个 cookie 问题。最后我找到了两个解决方案,可以帮助你。

Solution 1:

解决方案1:

yoursite/wp-login.php

yoursite/wp-login.php

Comment following lines 770-773

评论以下第 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.

它可能适用于某些网站,而某些网站可能会显示空白页面。此外,不建议这样做,因为此文件可能会在 wordpress 更新后被覆盖,因此请尝试第二种解决方案。

Solution 2:

解决方案2:

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

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.

更新您的主题也可能会丢失这些更改,因此请将此代码放在另一个functions.php 中,该文件位于您当前活动主题的 child-theme 文件夹下。希望能帮到你。

回答by Damien

Assuming you are running on a Unix/Linux type platform - please ensure you have copied your .htaccess file from your original server and updated any references to the old domain within that file. It will be in the root of your wordpress deployment (if you are using it).

假设您在 Unix/Linux 类型平台上运行 - 请确保您已从原始服务器复制 .htaccess 文件并更新该文件中对旧域的所有引用。它将位于您的 wordpress 部署的根目录中(如果您正在使用它)。

Either that or you may have a reference to your old domain somewhere in your wp_options table within the database.

或者您可能在数据库中的 wp_options 表中的某处引用了旧域。

Be forewarned that as you have moved from one domain to another, images and media locations within posts may need to be updated. You can either do that yourself directly within the database, use a find/replace utility or manually re-point your images within your posts. An alternative method to fix your post data is to export all your posts from your old site (from within the admin panel) - Tools > Export > All posts; then manually update the URL within that resultant file before importing to your new site.

请注意,当您从一个域转移到另一个域时,帖子中的图像和媒体位置可能需要更新。您可以直接在数据库中自己执行此操作,使用查找/替换实用程序或手动重新指向帖子中的图像。修复帖子数据的另一种方法是从旧站点(从管理面板内)导出所有帖子 - 工具 > 导出 > 所有帖子;然后在导入到新站点之前手动更新该结果文件中的 URL。

All of this and much more is covered over at codex.wordpress.org. For more information see this link:

所有这些以及更多内容都在codex.wordpress.org 中进行介绍。有关更多信息,请参阅此链接:

http://codex.wordpress.org/Changing_The_Site_URL

http://codex.wordpress.org/Changing_The_Site_URL

IMPORTANT NOTES:

重要笔记:

  1. If you are going to modify anything directly within the database, make sure you read the section that talks about GUIDs

  2. If you are using Better WP Security, there are other things you may need to do, but based on what you are describing, I doubt you have it installed.

  1. 如果您要直接在数据库中修改任何内容,请务必阅读有关 GUID 的部分

  2. 如果您使用的是Better WP Security您可能还需要做其他事情,但根据您的描述,我怀疑您是否安装了它。

回答by David Alsbright

I had the same problem with very similar circumstances and spec.

我在非常相似的情况和规格下遇到了同样的问题。

Eventually after trying all sorts of different solutions suggested online, I just renamed my active theme via FTP and then was able to login to the dashboard, I renamed my theme back and everything worked, I've no idea why but it may help somebody fix issues they're having.

最终,在尝试了网上建议的各种不同解决方案后,我只是通过 FTP 重命名了我的活动主题,然后能够登录到仪表板,我将主题重新命名,一切正常,我不知道为什么,但它可能有助于某人修复他们遇到的问题。