Recently I built a new PC and I ran into an issue where for some reason I couldn’t login to WordPress on my blog from the new PC. I could still login on my laptop, but not on my PC.
Every time I tried to login I got hit with the following error:
ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.
This appears to be quite a common error but none of the solutions I found for it seemed to work.
My browser was accepting cookies, they were definitely not disabled, I’d noticed that WordPress had recently auto updated to 3.8.1 so I assumed that was the problem and it would hopefully fix it’s self in the next update. Anyway it was working on my laptop so I could still login.
Then all of a sudden a couple of days ago my laptop stopped being able to login to WordPress with the same error…
I searched and searched for a solution, I edited themes, manually removed plugins, deleted themes, created my own plugins to explicitly set the cookie, tried to ensure the that domain was correct.
NOTHING WAS WORKING!
I’d seen some people say that a reinstall helped so I reinstalled WordPress, after taking a backup, and then copied back my wp-config.php because it had the login details for the database in it.
Hunting for a solution for a couple of hours I decided to check the error log…
I wish I’d done this earlier… The log was full of errors most of them had something along the lines of:
PHP Warning: Cannot modify header information – headers already sent by (output started at /home/ohmznet/public_html/wp-config.php:34)
Ok Lets look at wp-config.php… Lo and behold:
What’s that after the end tag of PHP script? Two new lines…
It turns out that the second you write anything to the actual page, the header gets written, which means that you can’t set cookies. That includes whitespace.
Those two blank lines broke my WordPress site so bad that I couldn’t login.
So yeah, I’ve learnt a lesson I should already know:
ALWAYS LOOK AT THE LOG FILES!