News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

[Trick] Redirect guests to the login page when trying to view a topic

Started by Robert., April 15, 2012, 12:17:18 PM

Previous topic - Next topic

Robert.

Index.php
Find
// Board is not empty... topic is not empty... action is empty.. Display!
else
{
require_once($sourcedir . '/Display.php');
return 'Display';
}

Replace with
// Board is not empty... topic is not empty... action is empty.. Display!
elseif(!empty($topic) && $context['user']['is_logged'])
{
require_once($sourcedir . '/Display.php');
return 'Display';
}
elseif(!empty($topic) && !$context['user']['is_logged']) {
require $sourcedir . '/LogInOut.php';
return 'Login';
}

And change
global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir
To
global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir, $context
Not heavily tested but should work :) Actually it shows the login page rather than redirecting, but it has the same effect.

Robert.

I have also packaged this in a mod and submitted this to the mod site. :)

Spectrum..!!


Existem pessoas que deixam de buscar algo que dura a vida toda, para somente conquistar algo que dura alguns momentos...
Ser humilde; não é ser menos que alguém. É saber que não somos mais que ninguém!
SMF 2.0.4 | Meu site -->
Dell Vostro 3560 + AMD Radeon™ HD 7670M 1GB| Windows 8 Pro | Fedora 18 | IE10 | Google Chrome

Não atendo PM para pedidos de suporte/ajuda

Colin

"If everybody is thinking alike, then somebody is not thinking." - Gen. George S. Patton Jr.

Colin

Adrek

Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

Robert.

You're welcome :)

@Phantomm: this mod has a very small difference in functionality. This mod just shows a login page when a guest tries to read topics. Hide Topics from Guests is a more advanced mod. :P

Just wondering though, does anyone have problems with this trick? I haven't got problems with it myself, but I was told that admins can't see topics either. =/ Doesn't happen to me though


Robert.


Adrek

and what if I want redirect guests to the login page only in selected boards?
is there any way to do this?
Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

Robert.

Yup, but it would require a few extra edits. I'm quite busy with other stuff right now, but I will look into it when I have some time. :)

Adrek

Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

shubha



fifacluborg

Quote from: 医生唱片骑师 on April 15, 2012, 12:17:18 PM
And change
global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir
To
global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir, $context
Not heavily tested but should work :) Actually it shows the login page rather than redirecting, but it has the same effect.
I not find this line! Can anyone tell me what file I find?
I did have searched in index.php and I not found nothing there... :(

Robert.

You can find that in the index.php in the root of your forum (there are multiple index.php, each directory has one :P). ;) Also, I'm planning to release an updated version soon (Thanks Labradoodle :) ). ;D

CHAOS-THEORY

u sir is ae pure genius,
i have searched for this kind of - S aech ai Tee - for 5 hours straigh, i can't feel ma eyes.
then suddenly this topic comes up; thanks dude.
and for your information posters, all the packages u provided aren't working anymore / deleted or  just drown; this one right here, this trick is working like ae boss in my latest SMF release.
respect earned
*GTA SA theme song playing* ill add u 

[edit]tt removed -- Illori

Colin

"If everybody is thinking alike, then somebody is not thinking." - Gen. George S. Patton Jr.

Colin

Advertisement: