[How to] Force guests to login/register to read topic content on certain boards

Started by Xhanch Studio, March 23, 2011, 12:57:45 AM

previous topic - next topic
Go Down

Xhanch Studio

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

Code Select
if (empty($topic))
    fatal_lang_error('no_board', false);

add some codes below those codes like this

Code Select
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(

$vis_ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$valid_ua = false;

foreach($bot_ua as $ua){
    if(strpos($vis_ua, $ua) !== false){
        $valid_ua = true;

if($context['user']['is_guest'] && in_array($board, $private_board) && !$valid_ua)
    redirectexit ('action=login');
Best Regards,
Susanto B.Sc
Web development services, WordPress plugin and theme development, PSD to XHTML conversion - http://xhanch.com
Read free manga online - http://authrone.com

Go Up