Forum
Notifications
Clear all
Topic starter
On certain boards, you may want to allow guests to see topics listings. But if they click a topic title, you want them to be redirected the login/register page. In other words, only registered members can read your topic contents on your exclusive boards.
You also can allow search engine (Google, Yahoo and so on) and social media (Twitter, FaceBook, MySpace, and so on) to read your topic contents with this small hack/modification so your forum will be visible to search engines.
This hack is applied to and tested on SMF 2.0 RC 5.
To force visitors to login/rgister in order to read the content of a topic on certain boards, you need to edit Sources/Display.php
Around line 81, find these codes
if (empty($topic))
fatal_lang_error('no_board', false);
add some codes below those codes like this
if (empty($topic))
fatal_lang_error('no_board', false);
//Define the board ID you want to protect. Lets say that you want to protect board 1, 3, 5 and 6
$private_board = array(1,3,5,6);
//Allowed user agents
$bot_ua = array(
'google',
'yahoo',
'facebook',
'twitter'
);
$vis_ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$valid_ua = false;
foreach($bot_ua as $ua){
if(strpos($vis_ua, $ua) !== false){
$valid_ua = true;
break;
}
}
if($context['user']['is_guest'] && in_array($board, $private_board) && !$valid_ua)
redirectexit ('action=login');
Posted : 23/03/2011 7:57 am