Welcome, Guest
Username: Password: Remember me
Got a Joomla problem? Post as much detail about it as you can here to see if you can get a solution.

Help others in the community - post your Joomla tips and how-tos here.
  • Page:
  • 1

TOPIC:

How to handle the Joomla 403 Forbidden Access message nicely. 5 months 2 weeks ago #8708

  • Terry
  • Terry's Avatar Topic Author
  • Offline
  • Administrator
  • Administrator
  • Posts: 52
  • Thank you received: 20
Hi,

I am looking for a nice solution to replace the ugly stock Joomla splash page to say you don't have access to view the content anymore. I am looking for a solution within Joomla if possible, not a redirect with .htaccess

The scenario I have is a registered person logs into a website and at some point gets distracted at some point on whatever page they were on and their session times out while they are away.

When they come back to their screen they select a link/button on the current page to go to content that is for registered(logged in) users only or refresh their current page, however they are no longer logged in so Joomla pops up the stock box saying they need to be logged in as pictured.


The URL is the expected URL for the page so there is nothing in the URL to say it is a 403 and this is why is seems tricky to pick up the failure has occurred.

The standard core Redirect component doesn't appear to be able to handle this situation from what I could try out as it is URL based.

I cannot be the first person to think the stock Joomla page is not something you want the end user/client to see.It would be nice to land them on a Login page ofr the front page.

Terry
.
Technical consulting, problem solving, custom development & programming and making square pegs fit in round holes with Joomla. You can find me at www.irataweb.com.au or 0409 942 896
Attachments:

Please Log in or Create an account to join the conversation.

Last edit: by Terry.

How to handle the Joomla 403 Forbidden Access message nicely. 5 months 1 week ago #8709

  • pjackson
  • pjackson's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 119
  • Thank you received: 36
There's a few ways to get a custom error page in your template.

docs.joomla.org/Custom_error_pages

JoomlaShack have a more comprehensive tutorial on it. The error page itself is a single page, but you can add conditions in for various errors like 403 to meet your needs. The code below would handle the redirection to various articles.
www.joomlashack.com/blog/joomla/404-pages/

Joomla.org.au has it implemented, however, as per the note on the Joomlashack article, it's a soft 404 - so I'm going
www.joomla.org.au/this-page-will-404
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access');

// 404 errors
if ($this->error->getCode() == '404') {
	header('Location: /404');
	exit;
}

// 403 errors
if ($this->error->getCode() == '403') {
	header('Location: /403');
	exit;
}

Will come back later with more header options to make the error page actually return the correct error so that google will register in particular 404 errors.
Patrick Jackson | Melbourne Australia | Certified Joomla Administrator
kps.fyi/pj
volunteers.joomla.org/joomlers/213-patrick-jackson
Australian Joomla Community: joomla.org.au/get-help

Please Log in or Create an account to join the conversation.

How to handle the Joomla 403 Forbidden Access message nicely. 5 months 1 week ago #8711

  • snaffle
  • snaffle's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 7
  • Thank you received: 4
Just be aware that if you use that method of redirecting you'll never find any broken links run through a link checker as the page redirects successfully.

As far as a link checker is concerned, the page has been found!

Much better option for standard error pages is to manually style the error.php with a logo and some links to key areas of the site including the Search page.

Please Log in or Create an account to join the conversation.

Last edit: by snaffle.

How to handle the Joomla 403 Forbidden Access message nicely. 5 months 1 week ago #8712

  • pjackson
  • pjackson's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 119
  • Thank you received: 36
Snaffle,

Agreed - which is what I was referring to about coming back later... turns out it's a link at the bottom of the Joomlashack post and that takes you here: www.joomlashack.com/blog/joomla/custom-404/

So the revised if statement for switching:
if ($this->error->getCode() == '404') {
     header("HTTP/1.0 404 Not Found");
     // Swap commenting if using gzip
     // https://www.joomlashack.com/blog/joomla/custom-404/
     echo file_get_contents(JURI::root().'404');
     //echo gzdecode(file_get_contents(JURI::root().'404'));
 exit;
 }

Which you'll now see a 404 on joomla.org.au/this-page-will-404 when you go to the network tab when you inspect the page.
Patrick Jackson | Melbourne Australia | Certified Joomla Administrator
kps.fyi/pj
volunteers.joomla.org/joomlers/213-patrick-jackson
Australian Joomla Community: joomla.org.au/get-help

Please Log in or Create an account to join the conversation.

Last edit: by pjackson.

How to handle the Joomla 403 Forbidden Access message nicely. 5 months 1 week ago #8713

  • snaffle
  • snaffle's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 7
  • Thank you received: 4
Ah yes, so you did.

Haven't seen that solution before which is much better if it works.

While it might show in the network panel though I'd be interested to see if it works with a link checker that crawls the site... not entirely convinced it work in that case.

Please Log in or Create an account to join the conversation.

How to handle the Joomla 403 Forbidden Access message nicely. 5 months 1 week ago #8714

  • pjackson
  • pjackson's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 119
  • Thank you received: 36
Just did a test on the 404 link I've used as an example above using www.drlinkcheck.com and it detected the 404.

It also detected 31 others 404s on the site :unsure: so will get to those soon. Most are images tied to CSS files.

The other thing that wasn't happening with the original technique was that the "Collect URLS" feature for the Joomla redirects plugin wasn't registering the 404 pages properly, so it wasn't collecting errors.

With the new code, that's also now resolved.
Patrick Jackson | Melbourne Australia | Certified Joomla Administrator
kps.fyi/pj
volunteers.joomla.org/joomlers/213-patrick-jackson
Australian Joomla Community: joomla.org.au/get-help
The following user(s) said Thank You: snaffle

Please Log in or Create an account to join the conversation.

How to handle the Joomla 403 Forbidden Access message nicely. 5 months 1 week ago #8715

  • pjackson
  • pjackson's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 119
  • Thank you received: 36
Terry,

For the 403 page, note that it's probably also worth making the article contain a login form to improve the UX - so if they get the 403 page, and they're needing to login, then they can.
Patrick Jackson | Melbourne Australia | Certified Joomla Administrator
kps.fyi/pj
volunteers.joomla.org/joomlers/213-patrick-jackson
Australian Joomla Community: joomla.org.au/get-help

Please Log in or Create an account to join the conversation.

How to handle the Joomla 403 Forbidden Access message nicely. 5 months 1 week ago #8716

  • snaffle
  • snaffle's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 7
  • Thank you received: 4
Thanks Patrick, that's really useful... also the suggestion on the 403 errors, with the login module.

Lot easier than styling the error.php page!

Please Log in or Create an account to join the conversation.

Last edit: by snaffle.

How to handle the Joomla 403 Forbidden Access message nicely. 5 months 1 week ago #8717

  • Terry
  • Terry's Avatar Topic Author
  • Offline
  • Administrator
  • Administrator
  • Posts: 52
  • Thank you received: 20
PJ,


thanks for playing.


I haven't had a chance to try some of your suggestions and I need to create a test environment that reliably reproduces the problem as it happens on the client site but not on my own local environment and randomly Joomla seems to handle it properly and pumps out a error message saying not auth'ed, please login in.

I will let you know how I go.

Regards,
Terry
Technical consulting, problem solving, custom development & programming and making square pegs fit in round holes with Joomla. You can find me at www.irataweb.com.au or 0409 942 896

Please Log in or Create an account to join the conversation.

How to handle the Joomla 403 Forbidden Access message nicely. 5 months 14 hours ago #8719

  • pjackson
  • pjackson's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 119
  • Thank you received: 36
PS: With the 404 part, if you happen to be testing the 404 page on a site that's offline, then you'll get a 503 Unavailable as the 404 pages won't be visible properly to file_get_contents.

Learnt that today in a convoluted way.

Using the Offline Preview plugin, adding your URL parameter to the end of the 404 URL code will bypass it during the site offline period.
Patrick Jackson | Melbourne Australia | Certified Joomla Administrator
kps.fyi/pj
volunteers.joomla.org/joomlers/213-patrick-jackson
Australian Joomla Community: joomla.org.au/get-help

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum