Page 1 of 3

403 Page to Login Redirect

Posted: Tue Mar 10, 2009 1:45 am
by drsassafras
I wanted to share this with the joomla community. When members visit an article when not logged in they get the very unhelpful 403 access restricted page. Its an easy template modification to move them to the login screen, but then they don't end up at the article they wanted when they login.

Here are step by step instruction on how to modify your default 1.5.9 joomla install to longin members and then send them to the page they requested.

I fumbled through most of it, so the code could probably be improved. If you can improve it, Post it here! Hopefully joomla will incorporate something like this into its default install.

First. Modify the /templates/system/error.php.

Find the line:
defined( '_JEXEC' ) or die( 'Restricted access' );
and the place the following code after the code above:
$ReferTo = $_SERVER['REQUEST_URI'];
$ReferTo = base64_encode($ReferTo);

if ($this->error->code = '403') {
header('Location:index.php?option=com_user&view=login&ReferTo='.$ReferTo); die();
}
Second. Modify the /components/com_user/views/login/tmpl/default_login.php

Search for:
<input type="hidden" name="return" value="<?php echo $this->return; ?>" />
And replace it with:
<input type="hidden" name="return" value="<?php if ($_GET['ReferTo']) echo $_GET['ReferTo']; else echo $this->return; ?>" />
There you have it. You should be all modified! I have included the 2 files in this message, so you can just overwrite the last ones as well. It might be easier then opening and modifying the code. But beware you are using the same version of joomla. ONLY modify the code yourself if you are using a different version.

Dr. Sassafras

Re: 403 Page to Login Redirect

Posted: Sun Mar 29, 2009 11:35 pm
by dreteh
Wow, your post is very helpful. I made the change and it works great.
Thanks for your sharing.

Re: 403 Page to Login Redirect

Posted: Mon Mar 30, 2009 12:36 am
by Webdongle
Is removing
defined( '_JEXEC' ) or die( 'Restricted access' );
such a good ides ?

It is put on Joomla files for a reason.

My mistake, just re-read it, i think i will need to lay off the booz before i read the posts. :-[

Re: 403 Page to Login Redirect

Posted: Mon Mar 30, 2009 1:22 am
by PastorAarn
I have been struggling with this issue for weeks and your simple solution fixed it for me in minutes. Thank you very much.

Re: 403 Page to Login Redirect

Posted: Mon Mar 30, 2009 11:43 am
by drsassafras
Webdongle wrote:Is removing
defined( '_JEXEC' ) or die( 'Restricted access' );
such a good ides ?\
Please read the instructions more closely. I specify putting the code after this line. Removing the code would allow this file to be called without being logged in... Now if it was a public access file, then I don't see the problem in it... But I am not really an expert and its all sort of off topic anyhow. Yes. Don't remove the code.

Re: 403 Page to Login Redirect

Posted: Mon Mar 30, 2009 12:24 pm
by drsassafras
PastorAarn wrote:I have been struggling with this issue for weeks and your simple solution fixed it for me in minutes. Thank you very much.
Yes, it took me the better part of a day to figure out how to do this. Glad I can save other people some time.

On another note, I just took at look at the upgrade package from joomla 1.5.9 to 1.5.10. The files we are working with here do not appear to be changed in 1.5.10. So, the instructions and the upgrade files should both work for 1.5.10 as well as 1.5.9.

Now, to be phenomenological about this, we need to see the file overwrites in action in order to be sure. If anyone can confirm that the files posted here do in fact work in 1.5.10, I am sure there would be other people who would appreciate the confirmation.

Re: 403 Page to Login Redirect

Posted: Tue Mar 31, 2009 2:23 am
by leolam
Webdongle wrote:My mistake, just re-read it, i think i will need to lay off the booz before i read the posts.
Sounds like a plan to me! 8)

Re: 403 Page to Login Redirect

Posted: Wed Apr 01, 2009 8:43 pm
by izabela
Hi,

Thank you very much drsassafras, the solution is great ;D
I did upgrade to 1.5.10 today and it looks it works as well.

Best regards,
Izabela

Re: 403 Page to Login Redirect

Posted: Sun Apr 19, 2009 5:43 pm
by o2plus2h
Is there a way to do this when using community builder?

Re: 403 Page to Login Redirect

Posted: Thu Apr 30, 2009 2:08 pm
by generator11
Just tried this with J1.5.10 and CB1.2 and it did not work. Worth a try though.

Re: 403 Page to Login Redirect

Posted: Tue Jun 09, 2009 4:58 am
by Will25
With the helpful hints that I get at this forum I will never really learn Joomla or PHP...
This "small" change really makes a difference. It makes my amateur page seem much more professional. A visitor can save a page to his favorites and later just click it - sign in and go right to the page. Just like a real web page! lol - thanks.

Re: 403 Page to Login Redirect

Posted: Fri Jun 12, 2009 12:10 pm
by Kualaho
Thanks. I posted similar problem several months ago without help. until a member posted this link. I will give it a try.

Re: 403 Page to Login Redirect

Posted: Wed Jun 17, 2009 3:37 pm
by dumini
Very good! I haven't thoroughly tested it but it worked the first time. Thank you.

Can't believe this is not a default thing here.

Re: 403 Page to Login Redirect

Posted: Fri Jul 17, 2009 8:33 pm
by a2purn
this nice sharing has been long time but it very helpfull, thank you very much :D

Re: 403 Page to Login Redirect

Posted: Thu Aug 06, 2009 1:30 am
by jazzking2001
i will try it now
it seems like a solution

Re: 403 Page to Login Redirect

Posted: Thu Aug 06, 2009 2:44 am
by jazzking2001
um have the latest Joomla 1.5.13
and i dont c
components/com_user/views/login/tmpl/default_login.php

any ideas?

also about part one of directions
i think that the link to login is different now
for my site its

http://www.neocrisis.com/component/comprofiler/login
i dont know its the same or not

Re: 403 Page to Login Redirect

Posted: Thu Aug 20, 2009 3:40 am
by jerryjurden
Wow, this worked, thanks so much!

RANT: It's REDICULOUS that a product this mature does not do this by default! It's utterly absurd that I have to hack the code to make this behave the way it should!!!!!

Re: 403 Page to Login Redirect

Posted: Thu Aug 20, 2009 4:10 am
by jazzking2001
jazzking2001 wrote:um have the latest Joomla 1.5.13
and i dont c
components/com_user/views/login/tmpl/default_login.php

any ideas?

also about part one of directions
i think that the link to login is different now
for my site its

http://www.neocrisis.com/component/comprofiler/login
i dont know its the same or not
any idea?

Re: 403 Page to Login Redirect

Posted: Mon Sep 28, 2009 11:20 am
by Beatleuk
Most awesome posting and it did exactly what I wanted it to do.

One further question, is there anyway to make the login form popup in front of the (blacked out) page they were on trying to access the restricted link from? to look something like this:
Image

Thanks for a great solution!

Re: 403 Page to Login Redirect

Posted: Fri Oct 09, 2009 2:35 pm
by sw373
Great post! I'm using 1.5.14 and the redirect goes to the login page as it should but it returns to the home page rather than the requested page. Any ideas on how I can get it to go to the requested page rather than the home page?

Re: 403 Page to Login Redirect

Posted: Sat Oct 31, 2009 2:07 am
by zoomlanski
Generator11, o2plus2h:

I made it work with Community Builder. I think I have 1.2 Stable.
Running Joomal Version 1.5.14

Upload the Error file in /templates/system - File still the same no change with this version

Change

if ($this->error->code = '403') {
header('Location:index.php?option=com_user&view=login&ReferTo='.$ReferTo); die();
}

if ($this->error->code = '403') {
header('Location:index.php?option=com_comprofiler&task=login&ReferTo='.$ReferTo); die();

Wow, this stuff is starting to make sense to me.
If someone can post this in CB forums that would be great.

Joomla rocks!
Thanks drsassafras for getting it started!


Tim

Re: 403 Page to Login Redirect

Posted: Sat Oct 31, 2009 6:13 pm
by Webdongle
sw373 wrote:Great post! I'm using 1.5.14 and the redirect goes to the login page as it should but it returns to the home page rather than the requested page. Any ideas on how I can get it to go to the requested page rather than the home page?
Try making the Menu Item to the page Reistered ?

Re: 403 Page to Login Redirect

Posted: Sun Nov 01, 2009 8:21 am
by jazzking2001
what file do we need to edit?
i am looking at templates/system/error.php but that page is for when page links do not work ect

Re: 403 Page to Login Redirect

Posted: Sun Nov 01, 2009 10:55 am
by Beatleuk
jazzking2001 wrote:what file do we need to edit?
i am looking at templates/system/error.php but that page is for when page links do not work ect
jazzking, the instructions are very clear and if you follow exactly what drsassafras says it works. 403 is an error, its a link that cannot be accessed unless you have the correct privledges. If you're not wanting what this post instructs then you should look elsewhere or post what you are really looking for but this does exactly what it says!

Re: 403 Page to Login Redirect

Posted: Sun Nov 08, 2009 3:41 pm
by SteinerPDP
zoomlanski: worked well for CB ... just don't forget the "}" at the end

... however, after the log-in I get directed to the front page and not to the article .. any ideas?

Re: 403 Page to Login Redirect

Posted: Sat Nov 21, 2009 4:08 pm
by Crash23
Can't make it work in version 1.5.14 (with no CB installed)

Can anyone offer asistance?

Thanks.

.............................................

Update, I disbled "Search Engine Friendly URLs" and it now redirects to the homepage. Not ideal as I would prefer search engine friendly URLs.

Any thoughts anyone ... thanks.

Re: 403 Page to Login Redirect

Posted: Sat Nov 21, 2009 8:50 pm
by Webdongle
There is an alternative...

* Create a separate menu that is not Activated.
* In that menu place a link to the page that is members only and set it Registered.
* In your main menu place a link to the link in the inactive menu and leave it set Public.

The users will see the link in your main menu. When that link is clicked by non logged in members the 'Please login..' will be displayed. After logging in the user will be directed to the target page.

Re: 403 Page to Login Redirect

Posted: Sun Nov 22, 2009 9:41 am
by Crash23
Thanks Webdongle,
Eventually got there. I initially used "Alias" on the wrong menu. All sorted now ... thanks again.

Re: 403 Page to Login Redirect

Posted: Fri Nov 27, 2009 4:50 pm
by a2purn
Hello,

I know my problem may be different from the cases above, but please help.
Is it possible to the default joomla login to be redirect to https? and if can be please any one help me... :( :-\
because I have tried using module parameters in the login does not work for specific login page only, because after redirected to https all the links changed to https.

Thanks,

Re: 403 Page to Login Redirect

Posted: Fri Nov 27, 2009 5:27 pm
by Webdongle
a2purn wrote:Hello,

I know my problem may be different from the cases above, but please help.
Is it possible to the default joomla login to be redirect to https? and if can be please any one help me... :( :-\
because I have tried using module parameters in the login does not work for specific login page only, because after redirected to https all the links changed to https.

Thanks,
Do you have SSL ?