最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Why is my staging subdomain not sending wordpress_logged_in cookies?

programmeradmin1浏览0评论

We have a custom login and account creation plugin. It works fine on our live environment (example) but not on our staging environment (test.example).

When we call wp_insert_user via an AJAX function, it successfully creates the user and returns their ID. wp_signon also appears to work. But in both cases, the user doesn't actually get logged in on the staging environment.

After looking through Chrome's developer tools, I realized that the live environment is sending set-cookie: wordpress_logged_in_... like it's supposed to, but the staging environment is not.

There's nothing in the error log about this, and it happens if we disable all of our other plugins on the staging environment.

What could be the cause of this? How can we make it send the login cookies like it's supposed to?

We have a custom login and account creation plugin. It works fine on our live environment (example) but not on our staging environment (test.example).

When we call wp_insert_user via an AJAX function, it successfully creates the user and returns their ID. wp_signon also appears to work. But in both cases, the user doesn't actually get logged in on the staging environment.

After looking through Chrome's developer tools, I realized that the live environment is sending set-cookie: wordpress_logged_in_... like it's supposed to, but the staging environment is not.

There's nothing in the error log about this, and it happens if we disable all of our other plugins on the staging environment.

What could be the cause of this? How can we make it send the login cookies like it's supposed to?

Share Improve this question edited Nov 1, 2020 at 11:34 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Dec 14, 2018 at 8:40 Pikamander2Pikamander2 6287 silver badges20 bronze badges 1
  • do you have any login mechanism on your staging env, to hide it from public? are URL path's in database correct? – André Kelling Commented Dec 14, 2018 at 10:25
Add a comment  | 

1 Answer 1

Reset to default 1

I noticed that the staging environment had different content in its wp-config.php and .htaccess files. I changed them to be closer to the ones on the live environment.

While I was there, I noticed that some of the differing content was related to various caching plugins that we previously had installed on the staging environment. In desperation, I reinstalled all of those plugins through wp-admin and then uninstalled them.

Surprisingly, that fixed the issue of the cookies not being sent. However, the cookies had incorrect paths or domains. After some trial and error, I finally got it working by adding these seven lines to wp-config.php:

define('ADMIN_COOKIE_PATH', '/wp-admin');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '/');
define('SITECOOKIEPATH', '/');
define('DOMAIN_CURRENT_SITE', 'test.example');
define('WP_HOME','https://test.example');
define('WP_SITEURL','https://test.example');

My assumption is that one or more of the caching plugins hadn't cleaned up after itself when we uninstalled it.

发布评论

评论列表(0)

  1. 暂无评论