- Posts: 36
- Thank you received: 1
Direct user to Log in Page instead of the 403 error page
- ADaniel
- Topic Author
- Offline
- Junior Member
-
Less
More
6 years 8 months ago #118500
by ADaniel
Direct user to Log in Page instead of the 403 error page was created by ADaniel
Our site is set up so the Home page is public, but all the menu items are for Registered users only. The Home page contains text indicating that to access the site, the user must login first. If they don't yet have an account, the "Create Account" link is right there on the front page for them to use.
However, we still have users who come to the site, land on the Home Page, and then attempt to access a page from the Main Menu BEFORE they have logged in.
When they do this they get the Joomla 403 error message. That message does not specifically tell them what the problem is (that they need to be a registered user who has logged in). What we want is for the user to be directed to the Log In menu instead of going to the 403 error page. So, anytime that the site would have given the user a 403 error page, we want them to go to the Log In screen instead.
There are several sets of instructions online with examples of how to edit Joomla's error.php file (move it first to the templates\TemplateName folder, edit it, etc.) There are examples of what code to put in the file, etc. However, it also appears that starting with Joomla 3.7.1, those previous instructions on editing and customizing error.php no longer apply. I can't find any examples online of editing Joomla 3.8.x's (which we are using), error.php file. I've tried some different edits of that code, but haven't struck on the exact edit that will work to redirect any 403 error to the Joomla Log In menu.
If anyone has successfully accomplished the above and can share the process, I would greatly appreciate it. Thank you -
However, we still have users who come to the site, land on the Home Page, and then attempt to access a page from the Main Menu BEFORE they have logged in.
When they do this they get the Joomla 403 error message. That message does not specifically tell them what the problem is (that they need to be a registered user who has logged in). What we want is for the user to be directed to the Log In menu instead of going to the 403 error page. So, anytime that the site would have given the user a 403 error page, we want them to go to the Log In screen instead.
There are several sets of instructions online with examples of how to edit Joomla's error.php file (move it first to the templates\TemplateName folder, edit it, etc.) There are examples of what code to put in the file, etc. However, it also appears that starting with Joomla 3.7.1, those previous instructions on editing and customizing error.php no longer apply. I can't find any examples online of editing Joomla 3.8.x's (which we are using), error.php file. I've tried some different edits of that code, but haven't struck on the exact edit that will work to redirect any 403 error to the Joomla Log In menu.
If anyone has successfully accomplished the above and can share the process, I would greatly appreciate it. Thank you -
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
-
6 years 8 months ago #118518
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Direct user to Log in Page instead of the 403 error page
Hi
I can see a few things here :
1. Why don't you set Access Level of the menu items to Registered? By doing that, users won't see the menu items until they logged in, so they won't be able to click on it and won't see the error
2. I never edited that error.php file before, so I don't really know. However, I don't think it's related to Joomla version, it should still work well. Maybe you are editing wrong file (in case you have multiple templates, you will have to edit the file in the right template). Not sure what code you added to the error.php file, I haven't tried but I think something like below should work:
Regards,
Tuan
I can see a few things here :
1. Why don't you set Access Level of the menu items to Registered? By doing that, users won't see the menu items until they logged in, so they won't be able to click on it and won't see the error
2. I never edited that error.php file before, so I don't really know. However, I don't think it's related to Joomla version, it should still work well. Maybe you are editing wrong file (in case you have multiple templates, you will have to edit the file in the right template). Not sure what code you added to the error.php file, I haven't tried but I think something like below should work:
Code:
$user = JFactory::getUser();
if ($this->error->getCode() == 403 && $user->get('guest'))
{
JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_users&view=login'));
}
Regards,
Tuan
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
-
6 years 8 months ago #118519
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Direct user to Log in Page instead of the 403 error page
Anyway, for this kind of question/issue, I think it's better to post it at
joomla.stackexchange.com/
or even Joomla facebook group
www.facebook.com/groups/joomlanospam/
There should be multiple users there face this issue before and hopefully, they can give you with solution
Tuan
There should be multiple users there face this issue before and hopefully, they can give you with solution
Tuan
Please Log in or Create an account to join the conversation.
- ADaniel
- Topic Author
- Offline
- Junior Member
-
Less
More
- Posts: 36
- Thank you received: 1
6 years 8 months ago #118579
by ADaniel
Replied by ADaniel on topic Direct user to Log in Page instead of the 403 error page
My client wants the menu items to be visible to anyone visiting the home page, but accessible to only those who log in. That's why I would like to handle this with a 403 page re-direct.
Thanks for the code tip I will experiment with that. The code you gave code is a bit different from the code examples others had used in previous Jooma versions (which do not work any longer).
Thanks for the code tip I will experiment with that. The code you gave code is a bit different from the code examples others had used in previous Jooma versions (which do not work any longer).
Please Log in or Create an account to join the conversation.
- ADaniel
- Topic Author
- Offline
- Junior Member
-
Less
More
- Posts: 36
- Thank you received: 1
6 years 8 months ago #118580
by ADaniel
Replied by ADaniel on topic Direct user to Log in Page instead of the 403 error page
Thanks for the suggestions. There are actually some ongoing discussions related to this topic on several online forums. None had a working solution yet.
I had just wondered if any of the other users of this forum, who maintain Joomla sites, had a working solution to this and could share how they solved it.
I had just wondered if any of the other users of this forum, who maintain Joomla sites, had a working solution to this and could share how they solved it.
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
-
6 years 8 months ago #118586
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Direct user to Log in Page instead of the 403 error page
If I understand your issue correctly, then the suggested code should work fine. Please try that and update us with the result
Tuan
Tuan
Please Log in or Create an account to join the conversation.
Moderators: Tuan Pham Ngoc
Support
Documentation
Information
Copyright © 2025 Joomla Extensions by Joomdonation. All Rights Reserved.
joomdonation.com is not affiliated with or endorsed by the Joomla! Project or Open Source Matters.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.