Page 1 of 1

[Snippet] Force login before you see anything V1

PostPosted: 10 May 2012, 11:23
by Sekuro
Force login before you see anything V1

Un-logged-in users see login-mask only.

Credit: BNa

Simple. Perfect. Cant be tricked out.

open

includes/functions.php

find

Code: Select all
        // The following assigns all _common_ variables that may be used at any point in a template.
        $template->assign_vars(array( 


before add

Code: Select all
        // "Force login before you see anything" for guests and bots / BNa / 2012
        $login_script_name = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME);
        
        if 
(($login_script_name !== 'ucp') && (($user->data['user_id'] == ANONYMOUS) || ($user->data['is_bot'])))
        {
        redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=login")); return;
        }
        // "Force login before you see anything" for guests and bots / BNa / 2012         


Each guest or bot, who visit your site, see only the login mask. Registering is possible, if active, bcs. of ucp.php?mode=register.

[Snippet] Force login before you see anything V1 - Addition

PostPosted: 10 May 2012, 11:24
by Sekuro
Addition V1

For a positiv-list (at example faq.php, additional to ucp.php), the code must be different.

Code: Select all

    
// "Force login before you see anything" for guests and bots / BNa / 2012
    $login_script_name = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME);

    if (($login_script_name == 'ucp') ||  ($login_script_name == 'faq'))
    {
    // do nothing
    }    
    else
{
    
    if 
(($user->data['user_id'] == ANONYMOUS) || ($user->data['is_bot']))
    {
    redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=login")); return;
    }

    }
    // "Force login before you see anything" for guests and bots / BNa / 2012                  

For more positiv-list entrys take a look at the syntax and the brackets

Code: Select all
    if (($login_script_name == 'ucp') ||  ($login_script_name == 'faq') || ($login_script_name == 'memberlist'))