I copied my entire existing install on a new staging server for some developmental work. Right now the craft/config/db.php file has not been changed and it is still connected to the production database.

The website loads fine on the dev server but I cannot login to the Craft admin. When I enter my login credentials, I get the following error in my chrome web console

Failed to load resource: the server responded with a status of 400 (Bad Request) /index.php?p=admin/actions/users/login

When I try to load the above URL (mydomain.com/index.php?p=admin/actions/users/login), I get a 404 page not found error.

The craft/config/general.php config file has the correct config for the dev server as far as I can tell. What am I missing here?

  • You won't be able to load mydomain.com/index.php?p=admin/actions/users/login directly in a browser because it's looking for a POST request. Can you enable devMode, reproduce the 400 Bad Request error, then edit the original question to share the whole stack trace?
    – Brad Bell
    Jun 9 '17 at 18:15
  • So I find the relevant portion in craft.log causing this 2017/06/09 18:41:08 [error] [exception.Craft\HttpException.400] Craft\HttpException: The CSRF token could not be verified. in /home/forge/dev.anstrex.info/craft/app/services/HttpRequestService.php:1337 2017/06/09 18:41:08 [trace] [system.CModule] Loading "errorHandler" application component in /home/forge/dev.anstrex.info/craft/app/etc/errors/ErrorHandler.php (281).
    – hvs
    Jun 9 '17 at 18:44
  • Also a phperrors.log file is generated that shows [09-Jun-2017 18:41:08 UTC] PHP Warning: Declaration of Craft\UserSessionService::login($username, $passwo rememberMe = false) should be compatible with CWebUser::login($identity, $duration = 0) in /home/forge/dev rex.info/craft/app/services/UserSessionService.php on line 17 [09-Jun-2017 18:41:08 UTC] PHP Warning: Declaration of Craft\UserSessionService::afterLogin() should be c ible with CWebUser::afterLogin($fromCookie) in /home/forge/dev.anstrex.info/craft/app/services/UserSession ce.php on line 17
    – hvs
    Jun 9 '17 at 18:45
  • The first error is the important one... do you have the enableCsrfProtection config setting enabled? Try disabling it on staging and see if that helps.
    – Brad Bell
    Jun 9 '17 at 22:20
  • I had enableCsrfProtection enabled for all domains(*). That was not the issue. While looking at the config file I realised that I had defaultCookieDomain => mydomain.com where as my staging server does not share that domain name. So after removing that entry from general.config, everything is working. Thanks for your help
    – hvs
    Jun 9 '17 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.