Message For Trying To Access Authenticated User Page

I have some pages that only authenticated users can access, so I set it up on my access rules. I want to write a small message to the user if they tried to access this page without being logged in.

Like “please login or register to view this content” however if the user goes to the login page directly (without redirect) this message shouldn’t appear.

I could set up 2 login pages, 1 for redirecting (with message) and another if the user goes directly to the login.

Is there a simple condition I can write instead?

Thanks

You can create your own WebUser component overriding CWebUser::accessDenied and set flash message there.

I think this would be the simplest solution.

PS. this is how you can create your own webuser component.

Thanks for the link, very helpful.

Worked like a charm :)