WordPress admin login cookies blocked error after moving servers

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:

Read More
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

Related posts

Leave a Reply

15 comments

  1. Having migrated hundreds of WP sites, here’s a few thoughts :

    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.

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

    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

    (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.

  2. 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
  3. 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' );
    
  4. I experienced this due to my caching plugin.

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

    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.

  5. 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');
    
  6. 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!

    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

    Cheers!

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

  8. 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).

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

    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.

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

    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.

  9. 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.

  10. 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
    
  11. 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' ] );
    
  12. I came across this error when trying to install a wordpress site on localhost. The problem was this line inside the .htaccess

    Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure

    It prevents cookies being set if not on https. Just had to remove the line.