Support » Fixing WordPress » Cookie Error when Logging In

Viewing 15 replies - 31 through 45 (of 115 total)
  • I’m not a php guru, but my understanding is that as long as the function is before the php closing tag it should be right.

    you could check the error logs in your control panel and see if it shows anything to let you know what’s wrong

    Which control panel do you mean? I cannot login to the admin screen of WordPress. Thanks for the help.

    Your webhosting control panel, such as cPanel or whatever your host uses.

    Eryone test logout???

    Cam

    (@crazycoolcam)

    Thanks for this thread. Was having intermittant issues with iOS Safari users being hit with the cookie error.

    Here’s the code I used to fix it (in a mu-plugin file):

    //fix for cookie error while login.
    function set_wp_test_cookie() {
    	setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
    	if ( SITECOOKIEPATH != COOKIEPATH )
    		setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
    }
    add_action( 'after_setup_theme', 'set_wp_test_cookie', 101 );

    Props to @mirajas for pointing me in the right direction. MU plugins by default seem to be loaded too early, so I had to wrap in a function and hook it.

    This allows my users, using BuddyPress and the sidebar login form, to not have to reenter their password on the wp-login.php page with the error saying that cookies are not supported.

    Thanks for this thread! Hope this additional info helps others.

    ~Cam

    Cam, where exactly did you put your code?…

    Basically I did a fresh installation of WordPress 3.7.1, on a new domain, and I get this cookies error, all the time (tried to login not 2, but 10 times, with no success).

    Any ideas, please?
    Cheers
    Alfredo

    Cam

    (@crazycoolcam)

    @alfjmrodrigues

    To use my block of code, you could do one (1) of the following:
    1. Paste the above code into functions.php of your active theme. (Downside is the fix won’t follow you between theme changes.)

    2. Create a mu-plugins directory. In the mu-plugins directory, create a file called “cookie-fix.php”. In the newly created blank php file, add the following code:

    <?php
    //fix for cookie error while login.
    function set_wp_test_cookie() {
    	setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
    	if ( SITECOOKIEPATH != COOKIEPATH )
    		setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
    }
    add_action( 'after_setup_theme', 'set_wp_test_cookie', 101 );
    ?>

    (Their isn’t much downside to this option except for a little more hassle factor on the front end. [i.e. setting up a mu-plugins folder, etc.]). I did this second option — except I placed the code in an already created mu-plugin file which holds all my custom code.

    Note that this edit simply sets the test cookie onto every page you visit. Setting the cookie early fixes the issue of it not being set when it checks during the login process. If you have cookies actually disabled, and cannot log in at all (even from yoursite.com/login.php) after two or three attempts, then this fix may not help.

    Let us know how it goes.
    ~Cam

    Greetings all,

    From what I’ve seen, this is caused by going to http://www.somesite.com/wordpress/wp-login.php, where all of the pages of the site are not www.

    First time you log in, it will have the test cookie on www subdomain, but not the actual somesite.com (real) domain. So it sends you to somesite.com/wordpress/wp-login.php again.

    So it’s sort of a failure of the new wp cookie checking mechanism, but the root of the problem seems to be wrong-domain url and cookies.

    Cam

    (@crazycoolcam)

    @programmin That definitely would cause the issue, but unless you have some interesting options set in your WP settings, my installs always seem to route me to either http://www.domain.com or domain.com depending on my site’s domain setting.

    Unless something has changed with how WP redirects based on your side domain setting (which is definitely possible), I can say that this was not the issue facing my site.

    ~Cam

    It looks like @programmin is right. In my dashboard I have set the www-CNAME as the preferred and I get the cookie error when I access it with the non-www-CNAME.

    If I go to http://mydomain.com/wp-login.php and try to log in (after deleting the cookie) it does not work. WordPress is not redirecting to the correct CNAME when I access the login page with the non-www CNAME.

    After getting the cookie error it THEN redirects me to the www-CNAME which is why it lets me log in the second time.

    However, if I manually type http://www.mydomain.com/wp-login.php it will let me login the first time and does not throw the error.

    I was able to solve the issue by using .htaccess to force the CNAME I want since WordPress is not doing it for some reason.

    # BEGIN Redirect non-www to www
    	RewriteCond %{HTTP_HOST} !^www\. [NC]
    	RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    # END Redirect non-www to www

    If you prefer to use the non-www CNAME you can add this code to your .htaccess

    # BEGIN Redirect www to non-www
    	RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
    	RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    # BEGIN Redirect www to non-www

    In order for this to fix the problem the CNAME you redirect to in your .htaccess must be the same CNAME specified in your dashboard. i.e., if you have specified http://domain.com in your dashboard, you need to redirect all www traffic to non-www traffic in .htaccess and vice versa.

    So at least this solves it (at least for me) without editing any core files.

    @cam I did exactly as you told, and no success.
    As this was a fresh installation, I had to create the mu-plugins folder and to create the cookie-fix.php file inside that folder.

    Did that on the local machine, uploaded it to the server, refreshed the page were I was testing the login on my site, and again, the same error…

    @cam here goes in a video my installation:

    It doesn’t work for me either. Rewriting non-www to www stops me at the login screen and gives me the faniliar message about not allowing cookies.
    Rewriting www to non-www leaves me with the blank screen. In the last case, using the Chrome debugger, I see execution stops at gmail.css(?).

    Did you clear your cache and delete all your cookies?

    If you are getting a white screen it sounds like more than a cookie problem to me, but I’m not a wordpress guru so who knows if it is or not.

    You might want to try reuploading your theme files and the core files and checking your database. Also, deactivate your plugins by renaming the folders or backup the folders and delete them from the server and see if there’s a plugin causing it.

    I’m not sure what gmail.css is, that sounds like something other than a wordpress core file?

Viewing 15 replies - 31 through 45 (of 115 total)
  • The topic ‘Cookie Error when Logging In’ is closed to new replies.