Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hi

I switched from the old member module to the new extended user module in v1.45, and immediately started having the 'cookie problem' - attempts to log in frustrated by an apparently erroneous error message 'Cookies must be enabled to use this CMS' even though cookies are enabled.

So I took a closer look.

I found that the error message always appeared on the first attempt to log in, but not after that. So I looked at auth.php, and experimented a bit with selectively deleting cookies, and found that the problem is with the test cookie. In auth.php, a test cookie is set and later retrieved - and if it's not there then the error message is generated.

The problem is explained under 'Common pitfalls' in the PHP documentation at http://php.net/manual/en/function.setcookie.php. The page has to be reloaded after the test cookie is set; otherwise it can't be retrieved. Somehow, my log-in form was invoking auth.php in a way that didn't involve the necessary page reload.

My workaround is to set the test cookie before the form is submitted, rather than waiting for auth.php to set it after the form is submitted. So, in the log-in template I include the tag

<cms:set_cookie 'couchcms_testcookie' 'CouchCMS test cookie' />


before the form tag. So far, it works!

I hope this might be useful if anyone else is having this problem with the new release.

Cheers
David
Thank you for sharing the solution with us David.

What you found out about the test cookie is absolutely correct.
However the <cms:process_login /> tag that sets the cookie as part of the authentication routine also immediately redirects (refreshes) the page (unless specifically instructed not to by setting the 'redirect' parameter to '0').

This redirection causes the page to reload and the cookie set in the previous load thus becomes available.

Somehow, my log-in form was invoking auth.php in a way that didn't involve the necessary page reload.
Which is what is puzzling and should be investigated.

Anyway, thanks for the workaround :)
2 posts Page 1 of 1