WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Cookie Error when Logging In (117 posts)

  1. willem.deboer
    Member
    Posted 5 months ago #

    Ah, I see. Mmm.

  2. willem.deboer
    Member
    Posted 5 months ago #

    Checked again, even restored wp-login.php from the original archive, just in case. Same white screen in two separate installs.
    I put the hack in functions.php at the end, above the "?>". Is that OK? I am familiar with programming conventions, just not with php.

  3. amsgator
    Member
    Posted 5 months ago #

    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

  4. willem.deboer
    Member
    Posted 5 months ago #

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

  5. amsgator
    Member
    Posted 5 months ago #

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

  6. jamesblackvn
    Member
    Posted 5 months ago #

    Eryone test logout???

  7. Cam
    Member
    Posted 5 months ago #

    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

  8. alfjmrodrigues
    Member
    Posted 5 months ago #

    Cam, where exactly did you put your code?...

  9. alfjmrodrigues
    Member
    Posted 5 months ago #

    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

  10. Cam
    Member
    Posted 5 months ago #

    @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

  11. programmin
    Member
    Posted 5 months ago #

    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.

  12. Cam
    Member
    Posted 5 months ago #

    @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

  13. amsgator
    Member
    Posted 5 months ago #

    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.

  14. alfjmrodrigues
    Member
    Posted 5 months ago #

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

  15. alfjmrodrigues
    Member
    Posted 5 months ago #

    @Cam here goes in a video my installation:

    http://www.youtube.com/watch?v=cTaXWCHMuxk&feature=youtu.be

  16. willem.deboer
    Member
    Posted 5 months ago #

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

  17. amsgator
    Member
    Posted 5 months ago #

    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?

  18. amsgator
    Member
    Posted 5 months ago #

    @alfjmrodrigues try commenting out wp-login.php like you did in the video but remove the mu-plugins folder and the file inside. delete all the functions.php hacks if you made any as well, and try just the wp-login.php comments by itself. does it still throw the white screen?

    If that doesn't work, install 3.7 and set all the settings, including your wordpress address and site address set to in your dashboard, then upgrade to 3.7.1 and see if it let's you login

  19. Cam
    Member
    Posted 5 months ago #

    @alfjmrodrigues

    Watched your video and have some further info.
    1. The mu-plugins folder goes into the wp-content folder (so it is right alongside the regular plugins folder). Otherwise, it looks as though you followed the other instructions of mind perfectly.

    However, I don't think this is your problem.

    What I would suggest for you to do is one of two things:
    1. Double check that cookies are indeed enabled in chrome: https://support.google.com/accounts/answer/61416?hl=en

    2. If that doesn't work (cookies were/are enabled), then I would suggest following the instructions on http://codex.wordpress.org/Changing_The_Site_URL to change your url from http://www.maiscashback.com to just http://maiscashback.com as both the home and the site url.

    Let us know how it goes.
    ~Cam

  20. amsgator
    Member
    Posted 5 months ago #

    @Cam I played around with both of my WordPress installations, and found that it does not matter if you have http://domain.com or http://www.domain.com set as the site URL and WordPress URL in the settings. You can use whichever you prefer.

    What DOES matter, is that if you have the settings set to http://domain.com then you MUST login from http://domain.com/wp-login.php and if you have the settings set to http://www.domain.com then you MUST login from http://www.domain.com/wp-login.php. Let me know if you found something different.

    The reason I posted the .htaccess redirect above is because my WordPress installations are not redirecting me from http://domain.com/wp-login.php to http://www.domain.com/wp-login.php (I have my site url and WordPress url set to http://www.domain.com) so I set it up so .htaccess does it for me.

  21. Cam
    Member
    Posted 5 months ago #

    @alfjmrodrigues

    One other thing to try (a 1b option since it is easier than #2) would be to switch browsers. It appears you are using Chrome. If you have Safari, IE, or Firefox installed, try logging in with one of those other browsers and see if it works. This will tell you it is the browser or the site.

    (FYI, I browsed over to your site, and was able to get the test cookie set without a problem [using Firefox]. I'm pretty sure you are facing a browser issue more than a WP issue.)

    ~Cam

  22. dlandri
    Member
    Posted 5 months ago #

    Mirajas and Cam,
    Many thanks for sharing your work. I've wrestled with this for days and would never have solved it on my own. You guys are great.

  23. willem.deboer
    Member
    Posted 5 months ago #

    I'm getting confused which of the patches to apply. Is just the one converting www to non-www and vise-versa enough or is the testcooky coding required as well?

  24. amsgator
    Member
    Posted 5 months ago #

    @alfjmrodrigues if this is a fresh install and you haven't even been able to login to set your wordpress and site URLs, try logging in from http://maiscashback.com/wp-login.php (without the www). If that works you can set the URLs in the dashboard and go from there. It may be looking for a cookie from http://maiscashback.com/ and not http://www.maiscashback.com/

  25. Cam
    Member
    Posted 5 months ago #

    @amsgator Agreed that it doesn't / shouldn't matter whether you use the www or not. And definitely agree that you must use the same .htaccess rewrite that you have setup in your WP dashboard settings. (I messed this up and was caught in an infinite loop error. Not fun, but funny once I had it fixed. :)

    I am simply giving options for @alfjmrodrigues to try for troubleshooting, because something doesn't work as expected. I'm pretty sure it is his browser settings after the last post. I visited the site and the test cookie set fine for me.

    ~Cam

  26. amsgator
    Member
    Posted 5 months ago #

    @willem.deboer I got mine to work with just the wp-login.php commenting OR just the .htaccess redirect. I prefer the htaccess redirect since it's not changing any core files that will be overwritten and flagged by wordfence

    I have not tried more than one at a time. If you have more than one going at a time it might be causing a conflict

  27. amsgator
    Member
    Posted 5 months ago #

    @Cam it sound like this is a fresh install and alfjmrodrigues hasn't even been able to set his URLs in the settings because he can't login. I'm wondering if WordPress isn't looking for a cookie from http://maiscashback.com/ instead of http://www.maiscashback.com/

    Does it let you set them during install? If so pass on this option.

    Since he is accessing it from http://www.maiscashback.com/ it's possible that is the issue.

  28. Cam
    Member
    Posted 5 months ago #

    @willem.deboer

    If you cannot login at all, first check your browser cookie settings and/or try using a different browser. (i.e if you use IE, try using chrome, or if you use chrome, try with Firefox or Safari.)

    If you cannot log in with a different browser, then you could try one of the patches above.

    The "//fix for cookie error while login" code I shared above works IF you get the error message after the first time you try to log in, but are able to log in on try #2 or #3. It won't help you if don't allow cookies to be set in your browser.

  29. Cam
    Member
    Posted 5 months ago #

    @amsgator, the cookie I received when visiting the site lists www in the host domain: http://www.maiscashback.com

    If it is setting the cookie fine for me (and not giving me the error), I am pretty confident it's his browser.

  30. willem.deboer
    Member
    Posted 5 months ago #

    @Cam @Amsgator Thank you, I'll give it a try!

Topic Closed

This topic has been closed to new replies.

About this Topic