Customizing SMF > Tips and Tricks
[Trick] Redirect guests to the login page when trying to view a topic
Doctor Deejay:
Index.php
Find
--- Code: --- // Board is not empty... topic is not empty... action is empty.. Display!
else
{
require_once($sourcedir . '/Display.php');
return 'Display';
}
--- End code ---
Replace with
--- Code: --- // 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';
}
--- End code ---
And change
--- Code: ---global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir
--- End code ---
To
--- Code: ---global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir, $context
--- End code ---
Not heavily tested but should work :) Actually it shows the login page rather than redirecting, but it has the same effect.
Doctor Deejay:
I have also packaged this in a mod and submitted this to the mod site. :)
Spectrum..!!:
Good, very good trick.
Thank you.
Colin:
Very helpful. Thanks!
phantomm:
I'm just curious, what is the difference between Hide Topics from Guests and this trick?
Navigation
[0] Message Index
[#] Next page
Go to full version